xref: /llvm-project/clang/test/Rewriter/rewrite-modern-struct-ivar.mm (revision 0f1c1be1968076d6f96f8a7bcc4a15cf195ecd97)
1// RUN: %clang_cc1 -E %s -o %t.mm
2// RUN: %clang_cc1 -fblocks -rewrite-objc -fms-extensions %t.mm -o %t-rw.cpp
3// RUN: FileCheck --input-file=%t-rw.cpp %s
4// RUN: %clang_cc1 -fsyntax-only -Werror -Wno-address-of-temporary -Wno-c++11-narrowing -std=c++11 -D"Class=void*" -D"id=void*" -D"SEL=void*" -U__declspec -D"__declspec(X)=" %t-rw.cpp
5
6struct S {
7    int i1;
8    double d1;
9    void (^block1)();
10};
11
12@interface I
13{
14  struct S struct_ivar;
15
16  struct S *pstruct_ivar;
17}
18@end
19
20@implementation I
21- (struct S) dMeth{ return struct_ivar; }
22@end
23
24// CHECK: return (*(struct S *)((char *)self + OBJC_IVAR_$_I$struct_ivar));
25
26@interface Foo{
27    @protected
28    struct {
29        int x:1;
30        int y:1;
31    } bar;
32
33    struct _S {
34        int x:1;
35        int y:1;
36    } s;
37
38}
39@end
40@implementation Foo
41- (void)x {
42  bar.x = 0;
43  bar.y = -1;
44
45  s.x = 0;
46  s.y = -1;
47}
48@end
49
50// CHECK: (*(decltype(((Foo_IMPL *)0U)->bar) *)((char *)self + OBJC_IVAR_$_Foo$bar)).x = 0;
51// CHECK: (*(struct _S *)((char *)self + OBJC_IVAR_$_Foo$s)).x = 0;
52