Debian Codegraph @

clang/test/Modules/merge-objc-interface.m

raw
1 // UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}}
2 // RUN: rm -rf %t
3 // RUN: split-file %s %t
4 // RUN: %clang_cc1 -emit-llvm -o %t/test.bc -F%t/Frameworks %t/test.m \
5 // RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
6 // RUN: %clang_cc1 -emit-llvm -o %t/test.bc -F%t/Frameworks %t/test-functions.m \
7 // RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
8
9 // Test a case when Objective-C interface ivars are present in two different modules.
10
11 //--- Frameworks/Foundation.framework/Headers/Foundation.h
12 @interface NSObject
13 @end
14
15 //--- Frameworks/Foundation.framework/Modules/module.modulemap
16 framework module Foundation {
17 header "Foundation.h"
18 export *
19 }
20
21 //--- Frameworks/ObjCInterface.framework/Headers/ObjCInterface.h
22 #import <Foundation/Foundation.h>
23 @interface ObjCInterface : NSObject {
24 @public
25 id _item;
26 }
27 @end
28
29 @interface WithBitFields : NSObject {
30 @public
31 int x: 3;
32 int y: 4;
33 }
34 @end
35
36 //--- Frameworks/ObjCInterface.framework/Modules/module.modulemap
37 framework module ObjCInterface {
38 header "ObjCInterface.h"
39 export *
40 }
41
42 //--- Frameworks/ObjCInterfaceCopy.framework/Headers/ObjCInterfaceCopy.h
43 #import <Foundation/Foundation.h>
44 @interface ObjCInterface : NSObject {
45 @public
46 id _item;
47 }
48 @end
49
50 @interface WithBitFields : NSObject {
51 @public
52 int x: 3;
53 int y: 4;
54 }
55 @end
56
57 // Inlined function present only in Copy.framework to make sure it uses decls from Copy module.
58 __attribute__((always_inline)) void inlinedIVarAccessor(ObjCInterface *obj, WithBitFields *bitFields) {
59 obj->_item = 0;
60 bitFields->x = 0;
61 }
62
63 //--- Frameworks/ObjCInterfaceCopy.framework/Modules/module.modulemap
64 framework module ObjCInterfaceCopy {
65 header "ObjCInterfaceCopy.h"
66 export *
67 }
68
69 //--- test.m
70 #import <ObjCInterface/ObjCInterface.h>
71 #import <ObjCInterfaceCopy/ObjCInterfaceCopy.h>
72
73 @implementation ObjCInterface
74 - (void)test:(id)item {
75 _item = item;
76 }
77 @end
78
79 @implementation WithBitFields
80 - (void)reset {
81 x = 0;
82 y = 0;
83 }
84 @end
85
86 //--- test-functions.m
87 #import <ObjCInterface/ObjCInterface.h>
88
89 void testAccessIVar(ObjCInterface *obj, id item) {
90 obj->_item = item;
91 }
92 void testAccessBitField(WithBitFields *obj) {
93 obj->x = 0;
94 }
95
96 #import <ObjCInterfaceCopy/ObjCInterfaceCopy.h>
97
98 void testAccessIVarLater(ObjCInterface *obj, id item) {
99 obj->_item = item;
100 }
101 void testAccessBitFieldLater(WithBitFields *obj) {
102 obj->y = 0;
103 }
104 void testInlinedFunction(ObjCInterface *obj, WithBitFields *bitFields) {
105 inlinedIVarAccessor(obj, bitFields);
106 }