* gcc.dg/stack-check-5.c: Skip with -fstack-protector.
[official-gcc.git] / gcc / testsuite / gcc.dg / addr_equal-1.c
blobdd237a7d3cdab996d338b71ad4b88a9eadb20f2f
1 /* { dg-do run } */
2 /* { dg-require-effective-target nonpic } */
3 /* { dg-require-weak "" } */
4 /* { dg-require-alias "" } */
5 /* { dg-options "-O2" } */
6 /* { dg-skip-if "" { powerpc-ibm-aix* } } */
7 void abort (void);
8 extern int undef_var0, undef_var1;
9 extern __attribute__ ((weak)) int weak_undef_var0;
10 extern __attribute__ ((weak)) int weak_undef_var1;
11 __attribute__ ((weak)) int weak_def_var0;
12 int def_var0=0, def_var1=0;
13 static int alias_var0 __attribute__ ((alias("def_var0")));
14 extern int weak_alias_var0 __attribute__ ((alias("def_var0"))) __attribute__ ((weak));
15 void undef_fn0(void);
16 void undef_fn1(void);
17 void def_fn0(void)
20 void def_fn1(void)
23 __attribute__ ((weak))
24 void weak_def_fn0(void)
27 __attribute__ ((weak))
28 void weak_def_fn1(void)
31 __attribute__ ((weak)) void weak_undef_fn0(void);
33 inline
34 void inline_fn0(void)
37 inline
38 void inline_fn1(void)
42 int
43 main(int argc, char **argv)
45 /* Two definitions are always different unless they can be interposed. */
46 if (!__builtin_constant_p (def_fn0 == def_fn1))
47 abort();
48 if (def_fn0 == def_fn1)
49 abort();
51 if (!__builtin_constant_p (&def_var0 == &def_var1))
52 abort();
53 if (&def_var0 == &def_var1)
54 abort();
56 /* Same symbol is the same no matter on interposition. */
57 if (!__builtin_constant_p (undef_fn0 != undef_fn0))
58 abort ();
59 if (undef_fn0 != undef_fn0)
60 abort ();
62 /* Do not get confused by same offset. */
63 if (!__builtin_constant_p (&undef_var0 + argc != &undef_var0 + argc))
64 abort ();
65 if (&undef_var0 + argc != &undef_var0 + argc)
66 abort ();
68 /* Alias and its target is equivalent unless one of them can be interposed. */
69 if (!__builtin_constant_p (&def_var0 != &alias_var0))
70 abort ();
71 if (&def_var0 != &alias_var0 )
72 abort ();
74 if (__builtin_constant_p (&def_var0 != &weak_alias_var0))
75 abort ();
76 if (&def_var0 != &weak_alias_var0)
77 abort ();
79 /* Weak definitions may be both NULL. */
80 if (__builtin_constant_p ((void *)weak_undef_fn0 == (void *)&weak_undef_var0))
81 abort ();
82 if ((void *)weak_undef_fn0 != (void *)&weak_undef_var0)
83 abort ();
85 /* Variables and functions do not share same memory locations otherwise. */
86 if (!__builtin_constant_p ((void *)undef_fn0 == (void *)&undef_var0))
87 abort ();
88 if ((void *)undef_fn0 == (void *)&undef_var0)
89 abort ();
91 /* This works for cases where one object is just weakly defined, too. */
92 if (!__builtin_constant_p ((void *)weak_undef_fn0 == (void *)&weak_def_var0))
93 abort ();
94 if ((void *)weak_undef_fn0 == (void *)&weak_def_var0)
95 abort ();
97 /* Inline functions are known to be different. */
98 if (!__builtin_constant_p (inline_fn0 != inline_fn1))
99 abort ();
100 if (inline_fn0 == inline_fn1)
101 abort ();
102 return 0;