Skip to content

Commit 048d2c7

Browse files
committed
[modules] Update visibility for merged ObjCInterfaceDecl definitions.
We keep using the first encountered definition and need to take into account visibility from subsequent definitions. For example, if the first definition is hidden and the second is visible, we need to make the first one visible too. rdar://82263843 Differential Revision: https://reviews.llvm.org/D110453
1 parent f5ee1ac commit 048d2c7

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1181,6 +1181,7 @@ void ASTDeclReader::MergeDefinitionData(ObjCInterfaceDecl *D,
11811181
if (DD.Definition != NewDD.Definition) {
11821182
Reader.MergedDeclContexts.insert(
11831183
std::make_pair(NewDD.Definition, DD.Definition));
1184+
Reader.mergeDefinitionVisibility(DD.Definition, NewDD.Definition);
11841185
}
11851186

11861187
// FIXME: odr checking?
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -F%t/Frameworks %t/test.m -DHIDDEN_FIRST=1 \
4+
// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
5+
// RUN: %clang_cc1 -emit-llvm -o %t/test.bc -F%t/Frameworks %t/test.m -DHIDDEN_FIRST=0 \
6+
// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
7+
8+
// Test a case when Objective-C interface is imported both as hidden and as visible.
9+
10+
//--- Frameworks/Foundation.framework/Headers/Foundation.h
11+
@interface NSObject
12+
@end
13+
14+
//--- Frameworks/Foundation.framework/Modules/module.modulemap
15+
framework module Foundation {
16+
header "Foundation.h"
17+
export *
18+
}
19+
20+
//--- Frameworks/Regular.framework/Headers/Regular.h
21+
#import <Foundation/Foundation.h>
22+
@interface Regular : NSObject
23+
@end
24+
25+
//--- Frameworks/Regular.framework/Modules/module.modulemap
26+
framework module Regular {
27+
header "Regular.h"
28+
export *
29+
}
30+
31+
//--- Frameworks/RegularHider.framework/Headers/Visible.h
32+
// Empty, file required to create a module.
33+
34+
//--- Frameworks/RegularHider.framework/Headers/Hidden.h
35+
#import <Foundation/Foundation.h>
36+
@interface Regular : NSObject
37+
@end
38+
39+
//--- Frameworks/RegularHider.framework/Modules/module.modulemap
40+
framework module RegularHider {
41+
header "Visible.h"
42+
export *
43+
44+
explicit module Hidden {
45+
header "Hidden.h"
46+
export *
47+
}
48+
}
49+
50+
//--- test.m
51+
52+
#if HIDDEN_FIRST
53+
#import <RegularHider/Visible.h>
54+
#import <Regular/Regular.h>
55+
#else
56+
#import <Regular/Regular.h>
57+
#import <RegularHider/Visible.h>
58+
#endif
59+
60+
@interface SubClass : Regular
61+
@end

0 commit comments

Comments
 (0)