1 /* { dg-do run { target { { nonpic || pie_enabled } && weak_undefined } } } */
2 /* { dg-require-alias "" } */
3 /* { dg-options "-O2 -fdelete-null-pointer-checks" } */
4 /* { dg-skip-if "function pointers can be NULL" { keeps_null_pointer_checks } } */
5 /* { dg-add-options weak_undefined } */
7 extern int undef_var0
, undef_var1
;
8 extern __attribute__ ((weak
)) int weak_undef_var0
;
9 extern __attribute__ ((weak
)) int weak_undef_var1
;
10 __attribute__ ((weak
)) int weak_def_var0
;
11 int def_var0
=0, def_var1
=0;
12 static int alias_var0
__attribute__ ((alias("def_var0")));
13 extern int weak_alias_var0
__attribute__ ((alias("def_var0"))) __attribute__ ((weak
));
22 __attribute__ ((weak
))
23 void weak_def_fn0(void)
26 __attribute__ ((weak
))
27 void weak_def_fn1(void)
30 __attribute__ ((weak
)) void weak_undef_fn0(void);
42 main(int argc
, char **argv
)
44 /* Two definitions are always different unless they can be interposed. */
45 if (!__builtin_constant_p (def_fn0
== def_fn1
))
47 if (def_fn0
== def_fn1
)
50 if (!__builtin_constant_p (&def_var0
== &def_var1
))
52 if (&def_var0
== &def_var1
)
55 /* Same symbol is the same no matter on interposition. */
56 if (!__builtin_constant_p (undef_fn0
!= undef_fn0
))
58 if (undef_fn0
!= undef_fn0
)
61 /* Do not get confused by same offset. */
62 if (!__builtin_constant_p (&undef_var0
+ argc
!= &undef_var0
+ argc
))
64 if (&undef_var0
+ argc
!= &undef_var0
+ argc
)
67 /* Alias and its target is equivalent unless one of them can be interposed. */
68 if (!__builtin_constant_p (&def_var0
!= &alias_var0
))
70 if (&def_var0
!= &alias_var0
)
73 if (__builtin_constant_p (&def_var0
!= &weak_alias_var0
))
75 if (&def_var0
!= &weak_alias_var0
)
78 /* Weak definitions may be both NULL. */
79 if (__builtin_constant_p ((void *)weak_undef_fn0
== (void *)&weak_undef_var0
))
81 if ((void *)weak_undef_fn0
!= (void *)&weak_undef_var0
)
84 /* Variables and functions do not share same memory locations otherwise. */
85 if (!__builtin_constant_p ((void *)undef_fn0
== (void *)&undef_var0
))
87 if ((void *)undef_fn0
== (void *)&undef_var0
)
90 /* This works for cases where one object is just weakly defined, too. */
91 if (!__builtin_constant_p ((void *)weak_undef_fn0
== (void *)&weak_def_var0
))
93 if ((void *)weak_undef_fn0
== (void *)&weak_def_var0
)
96 /* Inline functions are known to be different. */
97 if (!__builtin_constant_p (inline_fn0
!= inline_fn1
))
99 if (inline_fn0
== inline_fn1
)