blob: 140a980311e4eeaa68af5b07dcb6675674d2f5a4 [file] [log] [blame]
Chris Lattnerca790922009-04-21 19:55:16 +00001// RUN: clang-cc -triple x86_64-apple-darwin9 -verify -fsyntax-only %s
Daniel Dunbarff896662009-04-21 15:48:54 +00002
3@class I0;
Chris Lattnerca790922009-04-21 19:55:16 +00004
5// rdar://6811884
Chris Lattner1efaa952009-04-24 00:30:45 +00006int g0 = sizeof(I0); // expected-error{{invalid application of 'sizeof' to an incomplete type 'I0'}}
7
8// rdar://6821047
9void *g3(I0 *P) {
Chris Lattnerb5f15622009-04-24 23:50:08 +000010 P = P+5; // expected-error {{arithmetic on pointer to incomplete type 'I0 *'}}
11
Chris Lattner1efaa952009-04-24 00:30:45 +000012 return &P[4]; // expected-error{{subscript of pointer to incomplete type 'I0'}}
13}
14
15
Daniel Dunbarff896662009-04-21 15:48:54 +000016
17@interface I0 {
Chris Lattner1efaa952009-04-24 00:30:45 +000018@public
Daniel Dunbarff896662009-04-21 15:48:54 +000019 char x[4];
20}
21
22@property int p0;
23@end
24
25// size == 4
Chris Lattner1efaa952009-04-24 00:30:45 +000026int g1[ sizeof(I0) // expected-error {{invalid application of 'sizeof' to interface 'I0' in non-fragile ABI}}
Chris Lattnerca790922009-04-21 19:55:16 +000027 == 4 ? 1 : -1];
Daniel Dunbarff896662009-04-21 15:48:54 +000028
29@implementation I0
30@synthesize p0 = _p0;
31@end
32
33// size == 4 (we do not include extended properties in the
34// sizeof).
Chris Lattner1efaa952009-04-24 00:30:45 +000035int g2[ sizeof(I0) // expected-error {{invalid application of 'sizeof' to interface 'I0' in non-fragile ABI}}
Chris Lattnerca790922009-04-21 19:55:16 +000036 == 4 ? 1 : -1];
Daniel Dunbarff896662009-04-21 15:48:54 +000037
38@interface I1
39@property int p0;
40@end
41
42@implementation I1
43@synthesize p0 = _p0;
44@end
45
Fariborz Jahanian0468fb92009-04-21 20:28:41 +000046typedef struct { @defs(I1) } I1_defs; // expected-error {{invalid application of @defs in non-fragile ABI}}
47
Daniel Dunbarff896662009-04-21 15:48:54 +000048// 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 Lattner1efaa952009-04-24 00:30:45 +000051
52// rdar://6821047
53int bar(I0 *P) {
Chris Lattnerb5f15622009-04-24 23:50:08 +000054 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 Lattner1efaa952009-04-24 00:30:45 +000058 return P[4].x[2]; // expected-error {{subscript requires size of interface 'I0', which is not constant in non-fragile ABI}}
59}
60
Fariborz Jahanianced1e282009-04-24 17:34:33 +000061
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 Jahanian9f8a04f2009-07-16 17:59:14 +000080
81@interface Foo @end
82
83int 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}