Skip to content

Commit 4577887

Browse files
committed
[modules] Update visibility for merged ObjCProtocolDecl definitions.
Merge definition visibility the same way we do for other decls. Without the fix the added test emits `-Wobjc-method-access` as it cannot find a visible protocol. Make this warning `-Werror` so the test would fail when protocol visibility regresses. rdar://83600696 Differential Revision: https://reviews.llvm.org/D111860 (cherry picked from commit 7ad693a)
1 parent 76dffab commit 4577887

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,13 @@ void ASTDeclReader::ReadObjCDefinitionData(
12501250

12511251
void ASTDeclReader::MergeDefinitionData(ObjCProtocolDecl *D,
12521252
struct ObjCProtocolDecl::DefinitionData &&NewDD) {
1253+
struct ObjCProtocolDecl::DefinitionData &DD = D->data();
1254+
if (DD.Definition != NewDD.Definition) {
1255+
Reader.MergedDeclContexts.insert(
1256+
std::make_pair(NewDD.Definition, DD.Definition));
1257+
Reader.mergeDefinitionVisibility(DD.Definition, NewDD.Definition);
1258+
}
1259+
12531260
// FIXME: odr checking?
12541261
}
12551262

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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 -Werror=objc-method-access -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 -Werror=objc-method-access -DHIDDEN_FIRST=0 \
6+
// RUN: -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/modules.cache
7+
8+
// Test a case when Objective-C protocol 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/Common.framework/Headers/Common.h
21+
#import <Foundation/Foundation.h>
22+
@protocol Testing;
23+
@interface Common : NSObject
24+
- (id<Testing>)getProtocolObj;
25+
@end
26+
27+
//--- Frameworks/Common.framework/Modules/module.modulemap
28+
framework module Common {
29+
header "Common.h"
30+
export *
31+
}
32+
33+
//--- Frameworks/Regular.framework/Headers/Regular.h
34+
@protocol Testing
35+
- (void)protocolMethod;
36+
@end
37+
38+
//--- Frameworks/Regular.framework/Modules/module.modulemap
39+
framework module Regular {
40+
header "Regular.h"
41+
export *
42+
}
43+
44+
//--- Frameworks/RegularHider.framework/Headers/Visible.h
45+
// Empty, file required to create a module.
46+
47+
//--- Frameworks/RegularHider.framework/Headers/Hidden.h
48+
@protocol Testing
49+
- (void)protocolMethod;
50+
@end
51+
52+
//--- Frameworks/RegularHider.framework/Modules/module.modulemap
53+
framework module RegularHider {
54+
header "Visible.h"
55+
export *
56+
57+
explicit module Hidden {
58+
header "Hidden.h"
59+
export *
60+
}
61+
}
62+
63+
//--- test.m
64+
#import <Common/Common.h>
65+
66+
#if HIDDEN_FIRST
67+
#import <RegularHider/Visible.h>
68+
#import <Regular/Regular.h>
69+
#else
70+
#import <Regular/Regular.h>
71+
#import <RegularHider/Visible.h>
72+
#endif
73+
74+
void test(Common *obj) {
75+
[[obj getProtocolObj] protocolMethod];
76+
}

0 commit comments

Comments
 (0)