111
|
1 /* Test for constant expressions: broken optimization with const variables. */
|
|
2 /* Origin: Joseph Myers <jsm28@cam.ac.uk> */
|
|
3 /* { dg-do compile } */
|
|
4 /* { dg-options "-std=iso9899:1999 -O2" } */
|
|
5 /* Note: not using -pedantic since the -std option alone should be enough
|
|
6 to give the correct behavior to conforming programs. */
|
|
7
|
|
8 static const int ZERO = 0;
|
|
9 static const double DZERO = 0;
|
|
10
|
|
11 int *a;
|
|
12 int b;
|
|
13 long *c;
|
|
14
|
|
15 /* Assertion that n is a constant zero: so the conditional expression
|
|
16 has type 'int *' instead of 'void *'.
|
|
17 */
|
|
18 #define ASSERT_NPC(n) (b = *(1 ? a : (n)))
|
|
19 /* Assertion that n is not a constant zero: so the conditional
|
|
20 expressions has type 'void *' instead of 'int *'.
|
|
21 */
|
|
22 #define ASSERT_NOT_NPC(n) (c = (1 ? a : (void *)(__SIZE_TYPE__)(n)))
|
|
23
|
|
24 void
|
|
25 foo (void)
|
|
26 {
|
|
27 ASSERT_NPC (0);
|
|
28 ASSERT_NOT_NPC (ZERO);
|
|
29 ASSERT_NPC (0 + 0);
|
|
30 ASSERT_NOT_NPC (ZERO + 0); /* { dg-bogus "incompatible" "bogus null pointer constant" } */
|
|
31 ASSERT_NOT_NPC (ZERO + ZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" } */
|
|
32 ASSERT_NPC (+0);
|
|
33 ASSERT_NOT_NPC (+ZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" } */
|
|
34 ASSERT_NPC (-0);
|
|
35 ASSERT_NOT_NPC (-ZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" } */
|
|
36 ASSERT_NPC ((char) 0);
|
|
37 ASSERT_NOT_NPC ((char) ZERO);
|
|
38 ASSERT_NPC ((int) 0);
|
|
39 ASSERT_NOT_NPC ((int) ZERO);
|
|
40 ASSERT_NPC ((int) 0.0);
|
|
41 ASSERT_NOT_NPC ((int) DZERO);
|
|
42 ASSERT_NOT_NPC ((int) +0.0); /* { dg-bogus "incompatible" "bogus null pointer constant" } */
|
|
43 ASSERT_NOT_NPC ((int) (0.0+0.0)); /* { dg-bogus "incompatible" "bogus null pointer constant" } */
|
|
44 ASSERT_NOT_NPC ((int) (double)0.0); /* { dg-bogus "incompatible" "bogus null pointer constant" } */
|
|
45 }
|