Skip to content

Commit 42bc167

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 f07a9ff commit 42bc167

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
@@ -3211,16 +3211,20 @@ namespace {
32113211
d->getName() == "cos" || d->getName() == "exit";
32123212
};
32133213
if (decl->getOwningModule() &&
3214-
decl->getOwningModule()
3215-
->getTopLevelModule()
3216-
->getFullModuleName() == "std" &&
3217-
isAlternativeCStdlibFunctionFromTextualHeader(decl)) {
3214+
(decl->getOwningModule()
3215+
->getTopLevelModule()
3216+
->getFullModuleName() == "std" ||
3217+
decl->getOwningModule()
3218+
->getTopLevelModule()
3219+
->getFullModuleName() == "_SwiftConcurrencyShims")) {
3220+
if (isAlternativeCStdlibFunctionFromTextualHeader(decl)) {
3221+
return nullptr;
3222+
}
32183223
auto filename =
32193224
Impl.getClangPreprocessor().getSourceManager().getFilename(
32203225
decl->getLocation());
32213226
if (filename.endswith("cmath") || filename.endswith("math.h") ||
3222-
filename.endswith("stdlib.h") || filename.endswith("cstdlib") ||
3223-
filename.endswith("string.h")) {
3227+
filename.endswith("stdlib.h") || filename.endswith("cstdlib")) {
32243228
return nullptr;
32253229
}
32263230
}

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)