Skip to content

Commit 3ddab3e

Browse files
authored
Merge pull request #66897 from zoecarver/fix-scope-when-lookup
[cxx-interop] Use translation unit scope when doing lookups
2 parents 995c41c + 2114833 commit 3ddab3e

File tree

8 files changed

+26
-3
lines changed

8 files changed

+26
-3
lines changed

lib/ClangImporter/ClangAdapter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ clang::TypedefNameDecl *importer::findSwiftNewtype(const clang::NamedDecl *decl,
554554
clang::LookupResult lookupResult(clangSema, notificationName,
555555
clang::SourceLocation(),
556556
clang::Sema::LookupOrdinaryName);
557-
if (!clangSema.LookupName(lookupResult, nullptr))
557+
if (!clangSema.LookupName(lookupResult, clangSema.TUScope))
558558
return nullptr;
559559
auto nsDecl = lookupResult.getAsSingle<clang::TypedefNameDecl>();
560560
if (!nsDecl)

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2757,7 +2757,7 @@ ClangImporter::Implementation::lookupTypedef(clang::DeclarationName name) {
27572757
clang::SourceLocation(),
27582758
clang::Sema::LookupOrdinaryName);
27592759

2760-
if (sema.LookupName(lookupResult, /*scope=*/nullptr)) {
2760+
if (sema.LookupName(lookupResult, sema.TUScope)) {
27612761
for (auto decl : lookupResult) {
27622762
if (auto typedefDecl =
27632763
dyn_cast<clang::TypedefNameDecl>(decl->getUnderlyingDecl()))

lib/ClangImporter/ImportMacro.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@ static Optional<std::pair<llvm::APSInt, Type>>
328328
}
329329

330330
// Macro identifier.
331+
// TODO: for some reason when in C++ mode, "hasMacroDefinition" is often
332+
// false: rdar://110071334
331333
} else if (token.is(clang::tok::identifier) &&
332334
token.getIdentifierInfo()->hasMacroDefinition()) {
333335

@@ -422,7 +424,7 @@ static ValueDecl *importMacro(ClangImporter::Implementation &impl,
422424
auto diagState = impl.getClangSema().DelayedDiagnostics.push(diagPool);
423425
auto parsedType = impl.getClangSema().getTypeName(identifier,
424426
clang::SourceLocation(),
425-
/*scope*/nullptr);
427+
impl.getClangSema().TUScope);
426428
impl.getClangSema().DelayedDiagnostics.popWithoutEmitting(diagState);
427429

428430
if (parsedType && diagPool.empty()) {

test/ClangImporter/cf.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -typecheck -verify -import-cf-types -I %S/Inputs/custom-modules %s
22

3+
// RUN: %target-swift-frontend -disable-objc-attr-requires-foundation-module -typecheck -verify -import-cf-types -enable-experimental-cxx-interop -I %S/Inputs/custom-modules %s
4+
35
// REQUIRES: objc_interop
46

57
import CoreCooling

test/ClangImporter/macros.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-objc-interop -typecheck -verify %s
22

3+
// Most of these don't pass: rdar://110071334
4+
// %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-experimental-cxx-interop -enable-objc-interop -typecheck -verify %s
5+
36
@_exported import macros
47

58
func circle_area(_ radius: CDouble) -> CDouble {

test/Interop/Cxx/objc-correctness/Inputs/module.modulemap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@ module CxxClassWithNSStringInit [extern_c] {
1212
module NSOptionsMangling {
1313
header "NSOptionsMangling.h"
1414
}
15+
16+
module NSNofiticationBridging {
17+
header "nsnotification-bridging.h"
18+
requires objc
19+
requires cplusplus
20+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#import <Foundation/Foundation.h>
2+
3+
extern NSString * const SpaceShipNotification;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-swift-ide-test -print-module -module-to-print=NSNofiticationBridging -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop -enable-objc-interop | %FileCheck %s
2+
3+
// REQUIRES: objc_interop
4+
5+
// CHECK: import Foundation
6+
7+
// CHECK: let SpaceShipNotification: String

0 commit comments

Comments
 (0)