Skip to content

Commit d82ed63

Browse files
authored
Merge pull request #67020 from zoecarver/pick-math-and-tu-commits
2 parents 1777e9b + 4c21dd4 commit d82ed63

12 files changed

+100
-32
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
@@ -2712,7 +2712,7 @@ ClangImporter::Implementation::lookupTypedef(clang::DeclarationName name) {
27122712
clang::SourceLocation(),
27132713
clang::Sema::LookupOrdinaryName);
27142714

2715-
if (sema.LookupName(lookupResult, /*scope=*/nullptr)) {
2715+
if (sema.LookupName(lookupResult, sema.TUScope)) {
27162716
for (auto decl : lookupResult) {
27172717
if (auto typedefDecl =
27182718
dyn_cast<clang::TypedefNameDecl>(decl->getUnderlyingDecl()))

lib/ClangImporter/ImportDecl.cpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3197,19 +3197,30 @@ namespace {
31973197
// presence in the C++ standard library will cause overloading
31983198
// ambiguities or other type checking errors in Swift.
31993199
auto isAlternativeCStdlibFunctionFromTextualHeader =
3200-
[](const clang::FunctionDecl *d) -> bool {
3200+
[this](const clang::FunctionDecl *d) -> bool {
32013201
// stdlib.h might be a textual header in libc++'s module map.
32023202
// in this case, check for known ambiguous functions by their name
32033203
// instead of checking if they come from the `std` module.
32043204
if (!d->getDeclName().isIdentifier())
32053205
return false;
3206-
return d->getName() == "abs" || d->getName() == "div";
3206+
if (d->getName() == "abs" || d->getName() == "div")
3207+
return true;
3208+
if (Impl.SwiftContext.LangOpts.Target.isOSDarwin())
3209+
return d->getName() == "strstr" || d->getName() == "sin" ||
3210+
d->getName() == "cos" || d->getName() == "exit";
3211+
return false;
32073212
};
3208-
if (decl->getOwningModule() &&
3209-
(decl->getOwningModule()
3210-
->getTopLevelModule()
3211-
->getFullModuleName() == "std" ||
3212-
isAlternativeCStdlibFunctionFromTextualHeader(decl))) {
3213+
auto topLevelModuleEq =
3214+
[](const clang::FunctionDecl *d, StringRef n) -> bool {
3215+
return d->getOwningModule() &&
3216+
d->getOwningModule()
3217+
->getTopLevelModule()
3218+
->getFullModuleName() == n;
3219+
};
3220+
if (topLevelModuleEq(decl, "std")) {
3221+
if (isAlternativeCStdlibFunctionFromTextualHeader(decl)) {
3222+
return nullptr;
3223+
}
32133224
auto filename =
32143225
Impl.getClangPreprocessor().getSourceManager().getFilename(
32153226
decl->getLocation());
@@ -3218,6 +3229,13 @@ namespace {
32183229
return nullptr;
32193230
}
32203231
}
3232+
// Use the exit function from _SwiftConcurrency.h as it is platform
3233+
// agnostic.
3234+
if ((topLevelModuleEq(decl, "Darwin") ||
3235+
topLevelModuleEq(decl, "SwiftGlibc")) &&
3236+
decl->getDeclName().isIdentifier() && decl->getName() == "exit") {
3237+
return nullptr;
3238+
}
32213239
}
32223240

32233241
auto dc =

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

test/Interop/Cxx/stdlib/avoid-import-cxx-math.swift

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,17 @@
55
import CxxStdlib
66

77
func test() {
8-
let x: Float = 1.0
8+
let x: Double = 1.0
99
let y: Double = 2.0
1010

11-
// Note: we dispatch `pow(Float,Double)`
12-
// to ensure we don't pick up the
13-
// C++ stdlib `pow` function template.
14-
// The `pow` function is still reexported
15-
// from Darwin via CxxStdlib, so there are
16-
// matching overloads that can be found still.
17-
// Note: the error is different on Glibc instead
18-
// of Darwin, so do not check the exact error.
19-
let _ = CxxStdlib.pow(x, y) // expected-error {{}}
11+
let _ = pow(x, y)
2012

21-
let _ = CxxStdlib.abs(x) // expected-error {{module 'CxxStdlib' has no member named 'abs'}}
22-
let _ = CxxStdlib.div(x) // expected-error {{module 'CxxStdlib' has no member named 'div'}}
13+
let _ = abs(x)
14+
// https://github.com/apple/swift/issues/67006
15+
// let _ = div(42, 2)
16+
let _ = sin(x)
17+
let _ = cos(x)
18+
let _ = strstr("a", "aaa")
19+
20+
exit(0)
2321
}

test/Interop/Cxx/stdlib/print-swiftconcurrencyshims-interface.swift

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop -Xfrontend -disable-availability-checking %import-libdispatch -parse-as-library)
2+
//
3+
// REQUIRES: executable_test
4+
// REQUIRES: concurrency
5+
// REQUIRES: libdispatch
6+
// REQUIRES: concurrency_runtime
7+
8+
import StdlibUnittest
9+
10+
import CxxStdlib
11+
import Cxx
12+
13+
import _Concurrency
14+
import Dispatch
15+
16+
@main struct Main {
17+
static func main() async {
18+
var ConcurrencyTestSuite = TestSuite("Concurrency")
19+
20+
ConcurrencyTestSuite.test("Task.sleep") {
21+
let start = DispatchTime.now()
22+
await Task.sleep(100_000_000)
23+
let stop = DispatchTime.now()
24+
expectTrue(stop >= (start + .nanoseconds(100_000_000)))
25+
}
26+
27+
ConcurrencyTestSuite.test("Task.sleep (non-blocking)") {
28+
let task = detach {
29+
std.string("Hello, Swift!")
30+
}
31+
32+
await Task.sleep(100_000_000)
33+
expectEqual(await task.get(), "Hello, Swift!")
34+
}
35+
36+
await runAllTestsAsync()
37+
}
38+
}
39+

0 commit comments

Comments
 (0)