Skip to content

Commit c9de9e4

Browse files
committed
[cxx-interop] Re-work control flow when checking for duplicate functions.
Also add back `string.h` as a valid header and ban imports from `_SwiftConcurrencyShims`.
1 parent 20eb29a commit c9de9e4

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3208,16 +3208,20 @@ namespace {
32083208
d->getName() == "cos" || d->getName() == "exit";
32093209
};
32103210
if (decl->getOwningModule() &&
3211-
decl->getOwningModule()
3212-
->getTopLevelModule()
3213-
->getFullModuleName() == "std" &&
3214-
isAlternativeCStdlibFunctionFromTextualHeader(decl)) {
3211+
(decl->getOwningModule()
3212+
->getTopLevelModule()
3213+
->getFullModuleName() == "std" ||
3214+
decl->getOwningModule()
3215+
->getTopLevelModule()
3216+
->getFullModuleName() == "_SwiftConcurrencyShims")) {
3217+
if (isAlternativeCStdlibFunctionFromTextualHeader(decl)) {
3218+
return nullptr;
3219+
}
32153220
auto filename =
32163221
Impl.getClangPreprocessor().getSourceManager().getFilename(
32173222
decl->getLocation());
32183223
if (filename.endswith("cmath") || filename.endswith("math.h") ||
3219-
filename.endswith("stdlib.h") || filename.endswith("cstdlib") ||
3220-
filename.endswith("string.h")) {
3224+
filename.endswith("stdlib.h") || filename.endswith("cstdlib")) {
32213225
return nullptr;
32223226
}
32233227
}

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

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,13 @@ import CxxStdlib
66

77
func test() {
88
let x: Float = 1.0
9-
let y: Double = 2.0
9+
let y: Float = 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'}}
23-
let _ = CxxStdlib.strstr("a", "aaa") // expected-error {{module 'CxxStdlib' has no member named 'strstr'}}
13+
let _ = abs(x)
14+
let _ = div(42, 2)
15+
let _ = strstr("a", "aaa")
2416

2517
exit(0)
2618
}

0 commit comments

Comments
 (0)