xref: /llvm-project/clang/test/Modules/merge-anon-record-definition-in-objc.m (revision 7793e676514bc102e97a993e90257e8628069a8b)
1// UNSUPPORTED: target={{.*}}-zos{{.*}}, target={{.*}}-aix{{.*}}
2// RUN: rm -rf %t
3// RUN: split-file %s %t
4// RUN: %clang_cc1 -fsyntax-only -F%t/Frameworks %t/test.m -Wno-objc-property-implementation -Wno-incomplete-implementation \
5// RUN:            -fmodules -fmodule-name=Target -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
6
7// RUN: %clang_cc1 -fsyntax-only -F%t/Frameworks -x objective-c++ %t/test.m -Wno-objc-property-implementation -Wno-incomplete-implementation \
8// RUN:            -fmodules -fmodule-name=Target -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
9
10// Test anonymous TagDecl inside Objective-C interfaces are merged and ivars with these anonymous types are merged too.
11
12//--- Frameworks/Foundation.framework/Headers/Foundation.h
13@interface NSObject
14@end
15
16//--- Frameworks/Foundation.framework/Modules/module.modulemap
17framework module Foundation {
18  header "Foundation.h"
19  export *
20}
21
22//--- Frameworks/Target.framework/Headers/Target.h
23#import <Foundation/Foundation.h>
24@interface TestClass : NSObject {
25@public
26  struct {
27    struct { int x; int y; } left;
28    struct { int w; int z; } right;
29  } structIvar;
30  union { int x; float y; } *unionIvar;
31  enum { kX = 0, } enumIvar;
32}
33@property struct { int u; } prop;
34#ifndef __cplusplus
35- (struct { int v; })method;
36#endif
37@end
38
39@interface TestClass() {
40@public
41  struct { int y; } extensionIvar;
42}
43@end
44
45@implementation TestClass {
46@public
47  struct { int z; } implementationIvar;
48}
49@end
50
51//--- Frameworks/Target.framework/Modules/module.modulemap
52framework module Target {
53  header "Target.h"
54  export *
55}
56
57//--- Frameworks/Redirect.framework/Headers/Redirect.h
58#import <Target/Target.h>
59
60//--- Frameworks/Redirect.framework/Modules/module.modulemap
61framework module Redirect {
62  header "Redirect.h"
63  export *
64}
65
66//--- test.m
67// At first import everything as non-modular.
68#import <Target/Target.h>
69// And now as modular to merge same entities obtained through different sources.
70#import <Redirect/Redirect.h>
71// Non-modular import is achieved through using the same name (-fmodule-name) as the imported framework module.
72
73void test(TestClass *obj) {
74  obj->structIvar.left.x = 0;
75  obj->unionIvar->y = 1.0f;
76  obj->enumIvar = kX;
77  int tmp = obj.prop.u;
78#ifndef __cplusplus
79  tmp += [obj method].v;
80#endif
81
82  obj->extensionIvar.y = 0;
83  obj->implementationIvar.z = 0;
84}
85