i-c-e.c revision 32cb47174304bc7ec11478b9497c4e10f48273d9
1// RUN: %clang %s -ffreestanding -fsyntax-only -Xclang -verify -pedantic -fpascal-strings -std=c99
2
3#include <stdint.h>
4#include <limits.h>
5
6int a() {int p; *(1 ? &p : (void*)(0 && (a(),1))) = 10;} // expected-error {{incomplete type 'void' is not assignable}}
7
8// rdar://6091492 - ?: with __builtin_constant_p as the operand is an i-c-e.
9int expr;
10char w[__builtin_constant_p(expr) ? expr : 1];
11
12char v[sizeof(__builtin_constant_p(0)) == sizeof(int) ? 1 : -1];
13
14int implicitConversion = 1.0;
15char floatArith[(int)(1.0+2.0)]; // expected-warning {{must be an integer constant expression}}
16
17// __builtin_constant_p as the condition of ?: allows arbitrary foldable
18// constants to be transmogrified into i-c-e's.
19char b[__builtin_constant_p((int)(1.0+2.0)) ? (int)(1.0+2.0) : -1];
20
21struct c {
22  int a : (  // expected-error {{expression is not an integer constant expression}}
23           __builtin_constant_p((int)(1.0+2.0)) ? (int)(1.0+
24     expr  // expected-note {{subexpression not valid in an integer constant expression}}
25           ) : -1);
26};
27
28
29
30
31void test1(int n, int* p) { *(n ? p : (void *)(7-7)) = 1; }
32void test2(int n, int* p) { *(n ? p : (void *)0) = 1; }
33
34
35
36char array[1024/(sizeof (long))];
37
38int x['\xBb' == (char) 187 ? 1: -1];
39
40// PR1992
41void func(int x)
42{
43  switch (x) {
44    case sizeof("abc"): break;
45    case sizeof("loooong"): func(4);
46    case sizeof("\ploooong"): func(4);
47  }
48}
49
50
51// rdar://4213768
52int expr;
53char y[__builtin_constant_p(expr) ? -1 : 1];
54char z[__builtin_constant_p(4) ? 1 : -1];
55
56// Comma tests
57int comma1[0?1,2:3];  // expected-warning {{expression result unused}}
58int comma2[1||(1,2)]; // expected-warning {{expression result unused}} \
59                      // expected-warning {{use of logical '||' with constant operand}} \
60                      // expected-note {{use '|' for a bitwise operation}}
61int comma3[(1,2)]; // expected-warning {{size of static array must be an integer constant expression}} \
62					// expected-warning {{expression result unused}}
63
64// Pointer + __builtin_constant_p
65char pbcp[__builtin_constant_p(4) ? (intptr_t)&expr : 0]; // expected-error {{variable length array declaration not allowed at file scope}}
66
67int illegaldiv1a[1 || 1/0];  // expected-warning {{division by zero is undefined}}
68int illegaldiv1b[1 && 1/0];  // expected-warning {{division by zero is undefined}} expected-error{{variable length array declaration not allowed at file scope}}
69
70int illegaldiv2[1/0]; // expected-error {{variable length array declaration not allowed at file scope}} \
71                      // expected-warning {{division by zero is undefined}}
72int illegaldiv3[INT_MIN / -1]; // expected-error {{variable length array declaration not allowed at file scope}}
73// PR9262
74int illegaldiv4[0 / (1 / 0)]; // expected-warning {{division by zero is undefined}} expected-error {{variable length array declaration not allowed at file scope}}
75
76int chooseexpr[__builtin_choose_expr(1, 1, expr)];
77int realop[(__real__ 4) == 4 ? 1 : -1];
78int imagop[(__imag__ 4) == 0 ? 1 : -1];
79