Skip to content

Commit fc25044

Browse files
authored
Avoid C/C++ math function ambiguity for explicit module builds on Windows (#85609)
This tweaks the existing logic that disables the import of the C++ math functions to avoid ambiguity with the C math functions by handling the case where the module directory can be null in explicit module builds. For #85606
1 parent 6dece8a commit fc25044

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3893,9 +3893,10 @@ namespace {
38933893
if (auto file = sourceManager.getFileEntryRefForID(
38943894
sourceManager.getFileID(decl->getLocation()))) {
38953895
auto filename = file->getName();
3896-
if ((file->getDir() == owningModule->Directory) &&
3897-
(filename.ends_with("cmath") || filename.ends_with("math.h") ||
3898-
filename.ends_with("stdlib.h") || filename.ends_with("cstdlib"))) {
3896+
if (filename.ends_with("cmath") || filename.ends_with("math.h") ||
3897+
((filename.ends_with("stdlib.h") || filename.ends_with("cstdlib")) &&
3898+
decl->getDeclName().isIdentifier() &&
3899+
(decl->getName() == "abs" || decl->getName() == "div"))) {
38993900
return nullptr;
39003901
}
39013902
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// REQUIRES: OS=windows-msvc
2+
3+
// Test building the CRT module with C++ interop enabled on Windows
4+
5+
// RUN: %empty-directory(%t)
6+
// RUN: split-file %s %t
7+
// RUN: %target-swift-frontend -scan-dependencies -module-name Test \
8+
// RUN: -module-cache-path %t/clang-module-cache -disable-objc-interop \
9+
// RUN: -cxx-interoperability-mode=default \
10+
// RUN: -parse-stdlib -module-load-mode prefer-serialized \
11+
// RUN: %t/Test.swift -o %t/deps.json -I %t 2>&1
12+
13+
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json clang:SAL > %t/SAL.cmd
14+
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json clang:vcruntime > %t/vcruntime.cmd
15+
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json clang:SwiftShims > %t/SwiftShims.cmd
16+
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json Swift > %t/Swift.cmd
17+
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json clang:_Builtin_stddef > %t/_Builtin_stddef.cmd
18+
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json clang:corecrt > %t/corecrt.cmd
19+
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json clang:std_config > %t/std_config.cmd
20+
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json clang:_float > %t/_float.cmd
21+
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json clang:_fenv > %t/_fenv.cmd
22+
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json clang:_stdlib > %t/_stdlib.cmd
23+
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json clang:_malloc > %t/_malloc.cmd
24+
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json clang:_Builtin_intrinsics > %t/_Builtin_intrinsics.cmd
25+
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json clang:ucrt > %t/ucrt.cmd
26+
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json clang:std > %t/std.cmd
27+
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json clang:_complex > %t/_complex.cmd
28+
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json clang:SwiftOverlayShims > %t/SwiftOverlayShims.cmd
29+
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json CRT > %t/CRT.cmd
30+
31+
// Remove the candidate module file flag to force building from the swiftinterface file.
32+
// RUN: cat %t/CRT.cmd | sed '/candidate-module-file/d; /CRT.swiftmodule.*swiftmodule/d' > %t/CRT.mod.cmd
33+
34+
// RUN: %swift_frontend_plain @%t/SAL.cmd 2>&1
35+
// RUN: %swift_frontend_plain @%t/vcruntime.cmd 2>&1
36+
// RUN: %swift_frontend_plain @%t/SwiftShims.cmd 2>&1
37+
// RUN: %swift_frontend_plain @%t/Swift.cmd 2>&1
38+
// RUN: %swift_frontend_plain @%t/_Builtin_stddef.cmd 2>&1
39+
// RUN: %swift_frontend_plain @%t/corecrt.cmd 2>&1
40+
// RUN: %swift_frontend_plain @%t/std_config.cmd 2>&1
41+
// RUN: %swift_frontend_plain @%t/_float.cmd 2>&1
42+
// RUN: %swift_frontend_plain @%t/_fenv.cmd 2>&1
43+
// RUN: %swift_frontend_plain @%t/_stdlib.cmd 2>&1
44+
// RUN: %swift_frontend_plain @%t/_malloc.cmd 2>&1
45+
// RUN: %swift_frontend_plain @%t/_Builtin_intrinsics.cmd 2>&1
46+
// RUN: %swift_frontend_plain @%t/ucrt.cmd 2>&1
47+
// RUN: %swift_frontend_plain @%t/std.cmd 2>&1
48+
// RUN: %swift_frontend_plain @%t/_complex.cmd 2>&1
49+
// RUN: %swift_frontend_plain @%t/SwiftOverlayShims.cmd 2>&1
50+
// RUN: %swift_frontend_plain @%t/CRT.mod.cmd 2>&1
51+
52+
//--- Test.swift
53+
import CRT
54+

0 commit comments

Comments
 (0)