* fold-const.c (fold) [EQ_EXPR]: Place both integer and real
[official-gcc.git] / gcc / testsuite / gcc.dg / sequence-pt-1.c
blob5220227c43c34c266503567dc723b08968153a65
1 /* Test for sequence point warnings. */
2 /* Origin: Michael Meeks in
3 <URL:http://gcc.gnu.org/ml/gcc-patches/1998-06/msg00316.html>,
4 adapted to a testcase by Joseph Myers <jsm28@cam.ac.uk>. */
5 /* { dg-do compile } */
6 /* { dg-options "-Wsequence-point" } */
8 struct s
10 int a;
13 extern int fn (int);
14 extern int fnb (int, int);
15 extern int fnc (int *);
16 extern int sprintf (char *, const char *, ...);
18 typedef __SIZE_TYPE__ size_t;
20 void
21 foo (int a, int b, int n, int p, int *ptr, struct s *sptr,
22 int *ap, int *bp, int **cp, char *ans, int (*fnp[8])(int))
24 int len;
26 a = a++; /* { dg-warning "undefined" "sequence point warning" } */
27 a = --a; /* { dg-warning "undefined" "sequence point warning" } */
28 a = ++a + b; /* { dg-warning "undefined" "sequence point warning" } */
29 a = a-- + b; /* { dg-warning "undefined" "sequence point warning" } */
30 ap[n] = bp[n++]; /* { dg-warning "undefined" "sequence point warning" } */
31 ap[--n] = bp[n]; /* { dg-warning "undefined" "sequence point warning" } */
32 ap[++n] = bp[--n]; /* { dg-warning "undefined" "sequence point warning" } */
33 cp[n][n] = cp[n][n]++; /* { dg-warning "undefined" "sequence point warning" { xfail *-*-* } } */
34 cp[n][p] = cp[n][n++]; /* { dg-warning "undefined" "sequence point warning" } */
35 *ptr++ = (size_t)ptr++; /* { dg-warning "undefined" "sequence point warning" } */
36 sptr->a = sptr->a++; /* { dg-warning "undefined" "sequence point warning" { xfail *-*-* } } */
37 sptr->a = (size_t)(sptr++); /* { dg-warning "undefined" "sequence point warning" } */
38 *ptr++ = fn (*ptr); /* { dg-warning "undefined" "sequence point warning" } */
39 a = b = a++; /* { dg-warning "undefined" "sequence point warning" } */
40 b = a = --b; /* { dg-warning "undefined" "sequence point warning" } */
41 a = 1 + (a = 1); /* { dg-warning "undefined" "sequence point warning" } */
42 a = (a = b); /* { dg-warning "undefined" "sequence point warning" } */
43 a = (a = b) + 1; /* { dg-warning "undefined" "sequence point warning" } */
44 a = (bp[a++] = b) + 1; /* { dg-warning "undefined" "sequence point warning" } */
45 a = b++ * b++; /* { dg-warning "undefined" "sequence point warning" } */
46 a = fnb (b++, b++); /* { dg-warning "undefined" "sequence point warning" } */
47 a = (*fnp[b++]) (b++); /* { dg-warning "undefined" "sequence point warning" } */
48 a = (*fnp[b]) (b++); /* { dg-warning "undefined" "sequence point warning" } */
49 a = (*fnp[b++]) (b); /* { dg-warning "undefined" "sequence point warning" } */
50 *ap = fnc (ap++); /* { dg-warning "undefined" "sequence point warning" } */
51 (a += b) + (a += n); /* { dg-warning "undefined" "sequence point warning" } */
52 a = (b, b++) + (b++, b); /* { dg-warning "undefined" "sequence point warning" } */
53 ap[a++] += a; /* { dg-warning "undefined" "sequence point warning" } */
54 ap[a+=1] += a; /* { dg-warning "undefined" "sequence point warning" } */
55 ap[a++] += a++; /* { dg-warning "undefined" "sequence point warning" } */
56 ap[a+=1] += a++; /* { dg-warning "undefined" "sequence point warning" } */
57 a = a++, b = a; /* { dg-warning "undefined" "sequence point warning" } */
58 b = a, a = a++; /* { dg-warning "undefined" "sequence point warning" } */
59 a = (b++ ? n : a) + b; /* { dg-warning "undefined" "sequence point warning" { xfail *-*-* } } */
60 b ? a = a++ : a; /* { dg-warning "undefined" "sequence point warning" } */
61 b ? a : a = a++; /* { dg-warning "undefined" "sequence point warning" } */
62 b && (a = a++); /* { dg-warning "undefined" "sequence point warning" } */
63 (a = a++) && b; /* { dg-warning "undefined" "sequence point warning" } */
64 b, (a = a++); /* { dg-warning "undefined" "sequence point warning" } */
65 (a = a++), b; /* { dg-warning "undefined" "sequence point warning" } */
66 a ^= b ^= a ^= b; /* { dg-warning "undefined" "sequence point warning" } */
68 a = a; /* { dg-bogus "undefined" "bogus sequence point warning" } */
69 a = (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
70 a = ! (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
71 a = - (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
72 a = (double) (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
73 len = sprintf (ans, "%d", len++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
74 a = fn (a++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
75 b++, (b + b); /* { dg-bogus "undefined" "bogus sequence point warning" } */
76 (a = b++), (a = b++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
77 a = (b++, b++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
78 a = b++ && b++; /* { dg-bogus "undefined" "bogus sequence point warning" } */
79 a = b++ || b++; /* { dg-bogus "undefined" "bogus sequence point warning" } */
80 a = (b++ ? b++ : a); /* { dg-bogus "undefined" "bogus sequence point warning" } */
81 a = (b++ ? a : b++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
82 ap[a++] += bp[b]; /* { dg-bogus "undefined" "bogus sequence point warning" } */
83 ap[a += 1] += 1; /* { dg-bogus "undefined" "bogus sequence point warning" } */
84 *ptr < 128 ? *ptr++ : *(ptr += 2); /* { dg-bogus "undefined" "bogus sequence point warning" } */
86 /* The following will be represented internally with a tree consisting of
87 many duplicated SAVE_EXPRs. This caused the previous version of the
88 sequence point warning code to fail by running out of virtual memory. */
89 a = ((b & 1 ? 21 : 0)
90 | (b & 2 ? 22 : 0)
91 | (b & 3 ? 23 : 0)
92 | (b & 4 ? 24 : 0)
93 | (b & 5 ? 25 : 0)
94 | (b & 6 ? 26 : 0)
95 | (b & 7 ? 27 : 0)
96 | (b & 8 ? 28 : 0)
97 | (b & 9 ? 29 : 0)
98 | (b & 10 ? 30 : 0)
99 | (b & 11 ? 31 : 0)
100 | (b & 12 ? 32 : 0)
101 | (b & 13 ? 1 : 0)
102 | (b & 14 ? 2 : 0)
103 | (b & 15 ? 3 : 0)
104 | (b & 16 ? 4 : 0)
105 | (b & 17 ? 5 : 0)
106 | (b & 18 ? 6 : 0)
107 | (b & 19 ? 7 : 0)
108 | (b & 20 ? 8 : 0)
109 | (b & 21 ? 9 : 0));