Skip to content

Commit f9a1c4d

Browse files
committed
Fix class extension visibility bug
New code introduced for objcImp class extension support failed to check whether a class extension would be visible to Swift before importing it. This caused Swift to import extensions declared in private headers that ought not to be visible. Add the needed visibility check to the loop. Fixes rdar://123543707.
1 parent 59153a0 commit f9a1c4d

File tree

7 files changed

+34
-2
lines changed

7 files changed

+34
-2
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6013,8 +6013,13 @@ ClangCategoryLookupRequest::evaluate(Evaluator &evaluator,
60136013
llvm::TinyPtrVector<Decl *> results;
60146014
results.push_back(const_cast<ClassDecl *>(CD));
60156015

6016+
auto importer =
6017+
static_cast<ClangImporter *>(CD->getASTContext().getClangModuleLoader());
6018+
ClangImporter::Implementation &impl = importer->Impl;
6019+
60166020
for (auto clangExt : clangClass->known_extensions()) {
6017-
results.push_back(importCategory(clangExt));
6021+
if (impl.getClangSema().isVisible(clangExt))
6022+
results.push_back(importCategory(clangExt));
60186023
}
60196024

60206025
return results;

test/ClangImporter/Inputs/frameworks/Module.framework/Headers/Module.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ const char *getModuleVersion(void);
88
+alloc;
99
@end
1010

11+
@protocol ModuleProto @end
12+
1113
#define MODULE_H_MACRO 1
1214
#__private_macro MODULE_H_MACRO
1315

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
framework module Module_Private {
2+
umbrella "PrivateHeaders"
3+
explicit module * { export * }
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#import <Module/Module.h>
2+
3+
@interface Module () <ModuleProto>
4+
@property (readwrite) int extensionProperty;
5+
@end
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#import <Module/Module.h>

test/ClangImporter/diags_from_module.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import Module
3737
// CHECK-PRIMARY: diags_from_module.swift:[[@LINE-4]]:8: error: could not build Objective-C module 'Module'
3838

3939
// CHECK-WARN: Sub2.h:7:2: warning: here is some warning about something
40-
// CHECK-WARN: Module.h:20:1: warning: umbrella header for module 'Module' does not include header 'NotInModule.h'
40+
// CHECK-WARN: Module.h:22:1: warning: umbrella header for module 'Module' does not include header 'NotInModule.h'
4141
// FIXME: show [-Wincomplete-umbrella]
4242

4343
// CHECK-NO-WARN-NOT: warning about something
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-typecheck-verify-swift -F %S/Inputs/frameworks -module-cache-path %t/mcp1
3+
4+
// REQUIRES: objc_interop
5+
6+
import Module
7+
import Module_Private.Sub4
8+
9+
@_objcImplementation extension Module {
10+
// expected-error@-1 {{'@_objcImplementation' cannot be used to implement root class 'Module'}}
11+
// expected-warning@-2 {{extension for main class interface should provide implementation for class method 'version()'}}
12+
// expected-warning@-3 {{extension for main class interface should provide implementation for class method 'alloc()'}}
13+
}
14+
15+
extension Module: @retroactive ModuleProto {} // no-error

0 commit comments

Comments
 (0)