Chris Lattner | 4ef8dd6 | 2007-11-01 02:45:17 +0000 | [diff] [blame] | 1 | // RUN: clang %s -verify -fsyntax-only |
| 2 | |
Sebastian Redl | 392cf91 | 2009-02-07 00:23:52 +0000 | [diff] [blame] | 3 | #include <stdint.h> |
| 4 | |
Chris Lattner | 4ef8dd6 | 2007-11-01 02:45:17 +0000 | [diff] [blame] | 5 | typedef void (* fp)(void); |
| 6 | void foo(void); |
Douglas Gregor | f6c717c | 2009-01-23 16:54:12 +0000 | [diff] [blame] | 7 | |
| 8 | // PR clang/3377 |
| 9 | fp a[(short int)1] = { foo }; |
Chris Lattner | 4ef8dd6 | 2007-11-01 02:45:17 +0000 | [diff] [blame] | 10 | |
Chris Lattner | 4cc6271 | 2007-11-27 21:35:27 +0000 | [diff] [blame] | 11 | int myArray[5] = {1, 2, 3, 4, 5}; |
| 12 | int *myPointer2 = myArray; |
| 13 | int *myPointer = &(myArray[2]); |
| 14 | |
Chris Lattner | d411e04 | 2007-12-02 07:47:49 +0000 | [diff] [blame] | 15 | |
| 16 | extern int x; |
| 17 | void *g = &x; |
| 18 | int *h = &x; |
| 19 | |
Eli Friedman | a312ce2 | 2008-02-08 00:48:24 +0000 | [diff] [blame] | 20 | int test() { |
| 21 | int a[10]; |
Sebastian Redl | 9f4d863 | 2008-11-22 22:39:41 +0000 | [diff] [blame] | 22 | int b[10] = a; // expected-error {{initialization with '{...}' expected}} |
Chris Lattner | 1f6f54b | 2008-11-11 06:13:16 +0000 | [diff] [blame] | 23 | int +; // expected-error {{expected identifier or '('}} expected-error {{parse error}} |
Eli Friedman | a312ce2 | 2008-02-08 00:48:24 +0000 | [diff] [blame] | 24 | } |
Chris Lattner | be34ac6 | 2008-05-04 01:13:36 +0000 | [diff] [blame] | 25 | |
| 26 | |
| 27 | // PR2050 |
| 28 | struct cdiff_cmd { |
| 29 | const char *name; |
| 30 | unsigned short argc; |
| 31 | int (*handler)(); |
| 32 | }; |
| 33 | int cdiff_cmd_open(); |
| 34 | struct cdiff_cmd commands[] = { |
| 35 | {"OPEN", 1, &cdiff_cmd_open } |
| 36 | }; |
| 37 | |
Eli Friedman | 97c0a39 | 2008-05-21 03:39:11 +0000 | [diff] [blame] | 38 | // PR2348 |
| 39 | static struct { int z; } s[2]; |
| 40 | int *t = &(*s).z; |
| 41 | |
| 42 | // PR2349 |
| 43 | short *a2(void) |
| 44 | { |
| 45 | short int b; |
Chris Lattner | d880363 | 2008-08-10 01:58:45 +0000 | [diff] [blame] | 46 | static short *bp = &b; // expected-error {{initializer element is not a compile-time constant}} |
Eli Friedman | 97c0a39 | 2008-05-21 03:39:11 +0000 | [diff] [blame] | 47 | |
| 48 | return bp; |
| 49 | } |
Eli Friedman | f8f873d | 2008-05-30 18:07:22 +0000 | [diff] [blame] | 50 | |
| 51 | int pbool(void) { |
| 52 | typedef const _Bool cbool; |
| 53 | _Bool pbool1 = (void *) 0; |
| 54 | cbool pbool2 = &pbool; |
| 55 | return pbool2; |
| 56 | } |
| 57 | |
Chris Lattner | d5bac57 | 2008-08-19 00:58:40 +0000 | [diff] [blame] | 58 | |
| 59 | // rdar://5870981 |
| 60 | union { float f; unsigned u; } u = { 1.0f }; |
| 61 | |
Daniel Dunbar | 1e465df | 2008-08-25 20:08:27 +0000 | [diff] [blame] | 62 | // rdar://6156694 |
| 63 | int f3(int x) { return x; } |
| 64 | typedef void (*vfunc)(void); |
| 65 | void *bar = (vfunc) f3; |
Eli Friedman | b529d83 | 2008-09-02 09:37:00 +0000 | [diff] [blame] | 66 | |
| 67 | // PR2747 |
| 68 | struct sym_reg { |
| 69 | char nc_gpreg; |
| 70 | }; |
| 71 | int sym_fw1a_scr[] = { |
Nuno Lopes | 67c8601 | 2008-09-02 10:10:14 +0000 | [diff] [blame] | 72 | ((int)(&((struct sym_reg *)0)->nc_gpreg)) & 0, |
| 73 | 8 * ((int)(&((struct sym_reg *)0)->nc_gpreg)) |
Eli Friedman | b529d83 | 2008-09-02 09:37:00 +0000 | [diff] [blame] | 74 | }; |
Chris Lattner | e2f5619 | 2008-11-03 09:28:22 +0000 | [diff] [blame] | 75 | |
| 76 | // PR3001 |
Douglas Gregor | 275a369 | 2009-03-10 23:43:53 +0000 | [diff] [blame] | 77 | struct s1 s2 = { // expected-error{{tentative definition has type 'struct s1' that is never completed}} \ |
| 78 | // expected-note{{forward declaration of 'struct s1'}} |
Douglas Gregor | 4ec339f | 2009-01-19 19:26:10 +0000 | [diff] [blame] | 79 | .a = sizeof(struct s3), // expected-error {{invalid application of 'sizeof'}} \ |
| 80 | // expected-note{{forward declaration of 'struct s3'}} |
Chris Lattner | e2f5619 | 2008-11-03 09:28:22 +0000 | [diff] [blame] | 81 | .b = bogus // expected-error {{use of undeclared identifier 'bogus'}} |
| 82 | } |
| 83 | |
Anders Carlsson | 91b9f20 | 2009-01-24 17:47:50 +0000 | [diff] [blame] | 84 | // PR3382 |
| 85 | char t[] = ("Hello"); |
Douglas Gregor | d079b2d | 2009-01-30 17:42:28 +0000 | [diff] [blame] | 86 | |
| 87 | // <rdar://problem/6094855> |
| 88 | typedef struct { } empty; |
| 89 | |
| 90 | typedef struct { |
| 91 | empty e; |
| 92 | int i2; |
| 93 | } st; |
| 94 | |
| 95 | st st1 = { .i2 = 1 }; |
| 96 | |
| 97 | // <rdar://problem/6096826> |
| 98 | struct { |
| 99 | int a; |
| 100 | int z[2]; |
| 101 | } y = { .z = {} }; |
Douglas Gregor | d863517 | 2009-02-02 21:35:47 +0000 | [diff] [blame] | 102 | |
| 103 | int bbb[10]; |
| 104 | |
| 105 | struct foo2 { |
Eli Friedman | c91b7d9 | 2009-02-22 07:40:57 +0000 | [diff] [blame] | 106 | uintptr_t a; |
Douglas Gregor | d863517 | 2009-02-02 21:35:47 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | struct foo2 bar2[] = { |
Sebastian Redl | 392cf91 | 2009-02-07 00:23:52 +0000 | [diff] [blame] | 110 | { (intptr_t)bbb } |
Douglas Gregor | d863517 | 2009-02-02 21:35:47 +0000 | [diff] [blame] | 111 | }; |
Douglas Gregor | 7c53ca6 | 2009-02-18 22:23:55 +0000 | [diff] [blame] | 112 | |
| 113 | struct foo2 bar3 = { 1, 2 }; // expected-warning{{excess elements in struct initializer}} |
Eli Friedman | 91110ee | 2009-02-23 04:23:56 +0000 | [diff] [blame] | 114 | |
| 115 | int* ptest1 = __builtin_choose_expr(1, (int*)0, (int*)0); |
| 116 | |
| 117 | typedef int32_t ivector4 __attribute((vector_size(16))); |
| 118 | ivector4 vtest1 = 1 ? (ivector4){1} : (ivector4){1}; |
| 119 | ivector4 vtest2 = __builtin_choose_expr(1, (ivector4){1}, (ivector4){1}); |
| 120 | ivector4 vtest3 = __real__ (ivector4){1}; |
| 121 | ivector4 vtest4 = __imag__ (ivector4){1}; |
| 122 | |
Eli Friedman | 42edd0d | 2009-03-24 01:14:50 +0000 | [diff] [blame^] | 123 | uintptr_t ptrasintadd1 = (uintptr_t)&a - 4; |
| 124 | uintptr_t ptrasintadd2 = (uintptr_t)&a + 4; |
| 125 | uintptr_t ptrasintadd3 = 4 + (uintptr_t)&a; |