Skip to content

Commit 78002c1

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 a67f720 commit 78002c1

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
@@ -6103,8 +6103,13 @@ ClangCategoryLookupRequest::evaluate(Evaluator &evaluator,
61036103
llvm::TinyPtrVector<Decl *> results;
61046104
results.push_back(const_cast<ClassDecl *>(CD));
61056105

6106+
auto importer =
6107+
static_cast<ClangImporter *>(CD->getASTContext().getClangModuleLoader());
6108+
ClangImporter::Implementation &impl = importer->Impl;
6109+
61066110
for (auto clangExt : clangClass->known_extensions()) {
6107-
results.push_back(importCategory(clangExt));
6111+
if (impl.getClangSema().isVisible(clangExt))
6112+
results.push_back(importCategory(clangExt));
61086113
}
61096114

61106115
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)