Daniel Dunbar | 80737ad | 2009-12-15 22:01:24 +0000 | [diff] [blame] | 1 | // RUN: %clang %s -fsyntax-only -Xclang -verify -pedantic -fpascal-strings |
Chris Lattner | 04de993 | 2008-12-12 07:01:24 +0000 | [diff] [blame] | 2 | |
Eli Friedman | f04ec67 | 2009-02-27 04:46:32 +0000 | [diff] [blame] | 3 | #include <stdint.h> |
| 4 | #include <limits.h> |
| 5 | |
Eli Friedman | 09de176 | 2009-04-25 22:37:12 +0000 | [diff] [blame] | 6 | int a() {int p; *(1 ? &p : (void*)(0 && (a(),1))) = 10;} // expected-error {{incomplete type 'void' is not assignable}} |
Chris Lattner | 04de993 | 2008-12-12 07:01:24 +0000 | [diff] [blame] | 7 | |
| 8 | // rdar://6091492 - ?: with __builtin_constant_p as the operand is an i-c-e. |
| 9 | int expr; |
| 10 | char w[__builtin_constant_p(expr) ? expr : 1]; |
| 11 | |
Abramo Bagnara | 83a1c5c | 2010-10-09 04:51:06 +0000 | [diff] [blame] | 12 | char v[sizeof(__builtin_constant_p(0)) == sizeof(int) ? 1 : -1]; |
Chris Lattner | 04de993 | 2008-12-12 07:01:24 +0000 | [diff] [blame] | 13 | |
Chris Lattner | 42b83dd | 2008-12-12 18:00:51 +0000 | [diff] [blame] | 14 | // __builtin_constant_p as the condition of ?: allows arbitrary foldable |
| 15 | // constants to be transmogrified into i-c-e's. |
| 16 | char b[__builtin_constant_p((int)(1.0+2.0)) ? (int)(1.0+2.0) : -1]; |
| 17 | |
| 18 | struct c { |
| 19 | int a : ( // expected-error {{expression is not an integer constant expression}} |
| 20 | __builtin_constant_p((int)(1.0+2.0)) ? (int)(1.0+ |
| 21 | expr // expected-note {{subexpression not valid in an integer constant expression}} |
| 22 | ) : -1); |
| 23 | }; |
| 24 | |
| 25 | |
| 26 | |
Chris Lattner | 04de993 | 2008-12-12 07:01:24 +0000 | [diff] [blame] | 27 | |
| 28 | void test1(int n, int* p) { *(n ? p : (void *)(7-7)) = 1; } |
| 29 | void test2(int n, int* p) { *(n ? p : (void *)0) = 1; } |
| 30 | |
| 31 | |
| 32 | |
| 33 | char array[1024/(sizeof (long))]; |
| 34 | |
| 35 | int x['\xBb' == (char) 187 ? 1: -1]; |
| 36 | |
| 37 | // PR1992 |
| 38 | void func(int x) |
| 39 | { |
| 40 | switch (x) { |
| 41 | case sizeof("abc"): break; |
| 42 | case sizeof("loooong"): func(4); |
| 43 | case sizeof("\ploooong"): func(4); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | |
| 48 | // rdar://4213768 |
| 49 | int expr; |
| 50 | char y[__builtin_constant_p(expr) ? -1 : 1]; |
| 51 | char z[__builtin_constant_p(4) ? 1 : -1]; |
| 52 | |
Eli Friedman | f04ec67 | 2009-02-27 04:46:32 +0000 | [diff] [blame] | 53 | // Comma tests |
Argyrios Kyrtzidis | 1b2ad2f | 2010-09-19 23:03:35 +0000 | [diff] [blame] | 54 | int comma1[0?1,2:3]; // expected-warning {{expression result unused}} |
| 55 | int comma2[1||(1,2)]; // expected-warning {{expression result unused}} \ |
| 56 | // expected-warning {{use of logical || with constant operand}} |
| 57 | int comma3[(1,2)]; // expected-warning {{size of static array must be an integer constant expression}} \ |
| 58 | // expected-warning {{expression result unused}} |
Eli Friedman | f04ec67 | 2009-02-27 04:46:32 +0000 | [diff] [blame] | 59 | |
| 60 | // Pointer + __builtin_constant_p |
| 61 | char pbcp[__builtin_constant_p(4) ? (intptr_t)&expr : 0]; // expected-error {{variable length array declaration not allowed at file scope}} |
| 62 | |
Chris Lattner | 7ef655a | 2010-01-12 21:23:57 +0000 | [diff] [blame] | 63 | int illegaldiv1[1 || 1/0]; // expected-warning {{division by zero is undefined}} |
| 64 | int illegaldiv2[1/0]; // expected-error {{variable length array declaration not allowed at file scope}} \ |
| 65 | // expected-warning {{division by zero is undefined}} |
Eli Friedman | f04ec67 | 2009-02-27 04:46:32 +0000 | [diff] [blame] | 66 | int illegaldiv3[INT_MIN / -1]; // expected-error {{variable length array declaration not allowed at file scope}} |
| 67 | |
Eli Friedman | eb32fde | 2009-04-28 03:13:54 +0000 | [diff] [blame] | 68 | int chooseexpr[__builtin_choose_expr(1, 1, expr)]; |
| 69 | int realop[(__real__ 4) == 4 ? 1 : -1]; |
| 70 | int imagop[(__imag__ 4) == 0 ? 1 : -1]; |