xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/2008-07-30-redef-of-bitcasted-decl.c (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -emit-llvm -o - %s
2*f4a2713aSLionel Sambuc // <rdar://problem/6108358>
3*f4a2713aSLionel Sambuc 
4*f4a2713aSLionel Sambuc /* For posterity, the issue here begins initial "char []" decl for
5*f4a2713aSLionel Sambuc  * s. This is a tentative definition and so a global was being
6*f4a2713aSLionel Sambuc  * emitted, however the mapping in GlobalDeclMap referred to a bitcast
7*f4a2713aSLionel Sambuc  * of this global.
8*f4a2713aSLionel Sambuc  *
9*f4a2713aSLionel Sambuc  * The problem was that later when the correct definition for s is
10*f4a2713aSLionel Sambuc  * emitted we were doing a RAUW on the old global which was destroying
11*f4a2713aSLionel Sambuc  * the bitcast in the GlobalDeclMap (since it cannot be replaced
12*f4a2713aSLionel Sambuc  * properly), leaving a dangling pointer.
13*f4a2713aSLionel Sambuc  *
14*f4a2713aSLionel Sambuc  * The purpose of bar is just to trigger a use of the old decl
15*f4a2713aSLionel Sambuc  * sometime after the dangling pointer has been introduced.
16*f4a2713aSLionel Sambuc  */
17*f4a2713aSLionel Sambuc 
18*f4a2713aSLionel Sambuc char s[];
19*f4a2713aSLionel Sambuc 
bar(void * db)20*f4a2713aSLionel Sambuc static void bar(void *db) {
21*f4a2713aSLionel Sambuc   eek(s);
22*f4a2713aSLionel Sambuc }
23*f4a2713aSLionel Sambuc 
24*f4a2713aSLionel Sambuc char s[5] = "hi";
25*f4a2713aSLionel Sambuc 
foo()26*f4a2713aSLionel Sambuc int foo() {
27*f4a2713aSLionel Sambuc   bar(0);
28*f4a2713aSLionel Sambuc }
29