1 |
149 |
jeremybenn |
/* 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" } */
|
7 |
|
|
|
8 |
|
|
struct s
|
9 |
|
|
{
|
10 |
|
|
int a;
|
11 |
|
|
};
|
12 |
|
|
|
13 |
|
|
extern int fn (int);
|
14 |
|
|
extern int fnb (int, int);
|
15 |
|
|
extern int fnc (int *);
|
16 |
|
|
extern int sprintf (char *, const char *, ...);
|
17 |
|
|
|
18 |
|
|
typedef __SIZE_TYPE__ size_t;
|
19 |
|
|
|
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))
|
23 |
|
|
{
|
24 |
|
|
int len;
|
25 |
|
|
|
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" } */
|
60 |
|
|
b ? a = a++ : a; /* { dg-warning "undefined" "sequence point warning" } */
|
61 |
|
|
b && (a = a++); /* { dg-warning "undefined" "sequence point warning" } */
|
62 |
|
|
(a = a++) && b; /* { dg-warning "undefined" "sequence point warning" } */
|
63 |
|
|
b, (a = a++); /* { dg-warning "undefined" "sequence point warning" } */
|
64 |
|
|
(a = a++), b; /* { dg-warning "undefined" "sequence point warning" } */
|
65 |
|
|
a ^= b ^= a ^= b; /* { dg-warning "undefined" "sequence point warning" } */
|
66 |
|
|
|
67 |
|
|
a = a; /* { dg-bogus "undefined" "bogus sequence point warning" } */
|
68 |
|
|
a = (a++ && 4); /* { 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 = (double) (a++ && 4); /* { dg-bogus "undefined" "bogus sequence point warning" } */
|
72 |
|
|
len = sprintf (ans, "%d", len++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
|
73 |
|
|
a = fn (a++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
|
74 |
|
|
b++, (b + b); /* { dg-bogus "undefined" "bogus sequence point warning" } */
|
75 |
|
|
(a = b++), (a = b++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
|
76 |
|
|
a = (b++, 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++ : a); /* { dg-bogus "undefined" "bogus sequence point warning" } */
|
80 |
|
|
a = (b++ ? a : b++); /* { dg-bogus "undefined" "bogus sequence point warning" } */
|
81 |
|
|
ap[a++] += bp[b]; /* { dg-bogus "undefined" "bogus sequence point warning" } */
|
82 |
|
|
ap[a += 1] += 1; /* { dg-bogus "undefined" "bogus sequence point warning" } */
|
83 |
|
|
*ptr < 128 ? *ptr++ : *(ptr += 2); /* { dg-bogus "undefined" "bogus sequence point warning" } */
|
84 |
|
|
|
85 |
|
|
/* The following will be represented internally with a tree consisting of
|
86 |
|
|
many duplicated SAVE_EXPRs. This caused the previous version of the
|
87 |
|
|
sequence point warning code to fail by running out of virtual memory. */
|
88 |
|
|
a = ((b & 1 ? 21 : 0)
|
89 |
|
|
| (b & 2 ? 22 : 0)
|
90 |
|
|
| (b & 3 ? 23 : 0)
|
91 |
|
|
| (b & 4 ? 24 : 0)
|
92 |
|
|
| (b & 5 ? 25 : 0)
|
93 |
|
|
| (b & 6 ? 26 : 0)
|
94 |
|
|
| (b & 7 ? 27 : 0)
|
95 |
|
|
| (b & 8 ? 28 : 0)
|
96 |
|
|
| (b & 9 ? 29 : 0)
|
97 |
|
|
| (b & 10 ? 30 : 0)
|
98 |
|
|
| (b & 11 ? 31 : 0)
|
99 |
|
|
| (b & 12 ? 32 : 0)
|
100 |
|
|
| (b & 13 ? 1 : 0)
|
101 |
|
|
| (b & 14 ? 2 : 0)
|
102 |
|
|
| (b & 15 ? 3 : 0)
|
103 |
|
|
| (b & 16 ? 4 : 0)
|
104 |
|
|
| (b & 17 ? 5 : 0)
|
105 |
|
|
| (b & 18 ? 6 : 0)
|
106 |
|
|
| (b & 19 ? 7 : 0)
|
107 |
|
|
| (b & 20 ? 8 : 0)
|
108 |
|
|
| (b & 21 ? 9 : 0));
|
109 |
|
|
}
|