]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/SemaObjC/sizeof-interface.m
Vendor import of clang trunk r130700:
[FreeBSD/FreeBSD.git] / test / SemaObjC / sizeof-interface.m
1 // RUN: %clang_cc1 -fobjc-nonfragile-abi -verify -fsyntax-only %s
2
3 @class I0;
4
5 // rdar://6811884
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) {
10   P = P+5;        // expected-error {{arithmetic on pointer to incomplete type 'I0 *'}}
11
12   return &P[4];   // expected-error{{subscript of pointer to incomplete type 'I0'}}
13 }
14
15
16
17 @interface I0 {
18 @public
19   char x[4];
20 }
21
22 @property int p0;
23 @end
24
25 // size == 4
26 int g1[ sizeof(I0)     // expected-error {{invalid application of 'sizeof' to interface 'I0' in non-fragile ABI}}
27        == 4 ? 1 : -1];
28
29 @implementation I0
30 @synthesize p0 = _p0;
31 @end
32
33 // size == 4 (we do not include extended properties in the
34 // sizeof).
35 int g2[ sizeof(I0)   // expected-error {{invalid application of 'sizeof' to interface 'I0' in non-fragile ABI}}
36        == 4 ? 1 : -1];
37
38 @interface I1
39 @property int p0;
40 @end
41
42 @implementation I1
43 @synthesize p0 = _p0;
44 @end
45
46 typedef struct { @defs(I1); } I1_defs; // expected-error {{invalid application of @defs in non-fragile ABI}}
47
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];
51
52 // rdar://6821047
53 int bar(I0 *P) {
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   
58   return P[4].x[2];  // expected-error {{subscript requires size of interface 'I0', which is not constant in non-fragile ABI}}
59 }
60
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
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 }