Chris Lattner | ca79092 | 2009-04-21 19:55:16 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -triple x86_64-apple-darwin9 -verify -fsyntax-only %s |
Daniel Dunbar | ff89666 | 2009-04-21 15:48:54 +0000 | [diff] [blame] | 2 | |
| 3 | @class I0; |
Chris Lattner | ca79092 | 2009-04-21 19:55:16 +0000 | [diff] [blame] | 4 | |
| 5 | // rdar://6811884 |
Chris Lattner | 1efaa95 | 2009-04-24 00:30:45 +0000 | [diff] [blame] | 6 | int g0 = sizeof(I0); // expected-error{{invalid application of 'sizeof' to an incomplete type 'I0'}} |
| 7 | |
| 8 | // rdar://6821047 |
| 9 | void *g3(I0 *P) { |
Chris Lattner | b5f1562 | 2009-04-24 23:50:08 +0000 | [diff] [blame] | 10 | P = P+5; // expected-error {{arithmetic on pointer to incomplete type 'I0 *'}} |
| 11 | |
Chris Lattner | 1efaa95 | 2009-04-24 00:30:45 +0000 | [diff] [blame] | 12 | return &P[4]; // expected-error{{subscript of pointer to incomplete type 'I0'}} |
| 13 | } |
| 14 | |
| 15 | |
Daniel Dunbar | ff89666 | 2009-04-21 15:48:54 +0000 | [diff] [blame] | 16 | |
| 17 | @interface I0 { |
Chris Lattner | 1efaa95 | 2009-04-24 00:30:45 +0000 | [diff] [blame] | 18 | @public |
Daniel Dunbar | ff89666 | 2009-04-21 15:48:54 +0000 | [diff] [blame] | 19 | char x[4]; |
| 20 | } |
| 21 | |
| 22 | @property int p0; |
| 23 | @end |
| 24 | |
| 25 | // size == 4 |
Chris Lattner | 1efaa95 | 2009-04-24 00:30:45 +0000 | [diff] [blame] | 26 | int g1[ sizeof(I0) // expected-error {{invalid application of 'sizeof' to interface 'I0' in non-fragile ABI}} |
Chris Lattner | ca79092 | 2009-04-21 19:55:16 +0000 | [diff] [blame] | 27 | == 4 ? 1 : -1]; |
Daniel Dunbar | ff89666 | 2009-04-21 15:48:54 +0000 | [diff] [blame] | 28 | |
| 29 | @implementation I0 |
| 30 | @synthesize p0 = _p0; |
| 31 | @end |
| 32 | |
| 33 | // size == 4 (we do not include extended properties in the |
| 34 | // sizeof). |
Chris Lattner | 1efaa95 | 2009-04-24 00:30:45 +0000 | [diff] [blame] | 35 | int g2[ sizeof(I0) // expected-error {{invalid application of 'sizeof' to interface 'I0' in non-fragile ABI}} |
Chris Lattner | ca79092 | 2009-04-21 19:55:16 +0000 | [diff] [blame] | 36 | == 4 ? 1 : -1]; |
Daniel Dunbar | ff89666 | 2009-04-21 15:48:54 +0000 | [diff] [blame] | 37 | |
| 38 | @interface I1 |
| 39 | @property int p0; |
| 40 | @end |
| 41 | |
| 42 | @implementation I1 |
| 43 | @synthesize p0 = _p0; |
| 44 | @end |
| 45 | |
Fariborz Jahanian | 0468fb9 | 2009-04-21 20:28:41 +0000 | [diff] [blame] | 46 | typedef struct { @defs(I1) } I1_defs; // expected-error {{invalid application of @defs in non-fragile ABI}} |
| 47 | |
Daniel Dunbar | ff89666 | 2009-04-21 15:48:54 +0000 | [diff] [blame] | 48 | // FIXME: This is currently broken due to the way the record layout we |
| 49 | // create is tied to whether we have seen synthesized properties. Ugh. |
| 50 | // int g3[ sizeof(I1) == 0 ? 1 : -1]; |
Chris Lattner | 1efaa95 | 2009-04-24 00:30:45 +0000 | [diff] [blame] | 51 | |
| 52 | // rdar://6821047 |
| 53 | int bar(I0 *P) { |
Chris Lattner | b5f1562 | 2009-04-24 23:50:08 +0000 | [diff] [blame] | 54 | P = P+5; // expected-error {{arithmetic on pointer to interface 'I0', which is not a constant size in non-fragile ABI}} |
| 55 | P = 5+P; // expected-error {{arithmetic on pointer to interface 'I0', which is not a constant size in non-fragile ABI}} |
| 56 | P = P-5; // expected-error {{arithmetic on pointer to interface 'I0', which is not a constant size in non-fragile ABI}} |
| 57 | |
Chris Lattner | 1efaa95 | 2009-04-24 00:30:45 +0000 | [diff] [blame] | 58 | return P[4].x[2]; // expected-error {{subscript requires size of interface 'I0', which is not constant in non-fragile ABI}} |
| 59 | } |
| 60 | |
Fariborz Jahanian | ced1e28 | 2009-04-24 17:34:33 +0000 | [diff] [blame] | 61 | |
| 62 | @interface I @end |
| 63 | |
| 64 | @interface XCAttributeRunDirectNode |
| 65 | { |
| 66 | @public |
| 67 | unsigned long attributeRuns[1024 + sizeof(I)]; // expected-error {{invalid application of 'sizeof' to interface 'I' in non-fragile ABI}} |
| 68 | int i; |
| 69 | } |
| 70 | @end |
| 71 | |
| 72 | @implementation XCAttributeRunDirectNode |
| 73 | |
| 74 | - (unsigned long)gatherStats:(id )stats |
| 75 | { |
| 76 | return attributeRuns[i]; |
| 77 | } |
| 78 | @end |
| 79 | |
Fariborz Jahanian | 9f8a04f | 2009-07-16 17:59:14 +0000 | [diff] [blame] | 80 | |
| 81 | @interface Foo @end |
| 82 | |
| 83 | int foo() |
| 84 | { |
| 85 | Foo *f; |
| 86 | |
| 87 | // Both of these crash clang nicely |
| 88 | ++f; // expected-error {{arithmetic on pointer to interface 'Foo', which is not a constant size in non-fragile ABI}} |
| 89 | --f; // expected-error {{arithmetic on pointer to interface 'Foo', which is not a constant size in non-fragile ABI}} |
| 90 | } |