diff --git a/include/swift/AST/KnownIdentifiers.def b/include/swift/AST/KnownIdentifiers.def index eb27e90a77400..6b920e691c255 100644 --- a/include/swift/AST/KnownIdentifiers.def +++ b/include/swift/AST/KnownIdentifiers.def @@ -60,6 +60,7 @@ IDENTIFIER(CoreFoundation) IDENTIFIER(count) IDENTIFIER(CVarArg) IDENTIFIER(Cxx) +IDENTIFIER(CxxStdlib) IDENTIFIER(Darwin) IDENTIFIER(Distributed) IDENTIFIER(dealloc) diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index 3a2466ba61597..1fb449eb723d2 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -2001,6 +2001,14 @@ ClangImporter::loadModule(SourceLoc importLoc, ModuleDecl *ClangImporter::Implementation::loadModule( SourceLoc importLoc, ImportPath::Module path) { ModuleDecl *MD = nullptr; + ASTContext &ctx = getNameImporter().getContext(); + + if (path.front().Item == ctx.Id_CxxStdlib) { + ImportPath::Builder adjustedPath(ctx.getIdentifier("std"), importLoc); + adjustedPath.append(path.getSubmodulePath()); + path = adjustedPath.get().getModulePath(ImportKind::Module); + } + if (!DisableSourceImport) MD = loadModuleClang(importLoc, path); if (!MD) diff --git a/test/Interop/Cxx/stdlib/libcxx-module-interface.swift b/test/Interop/Cxx/stdlib/libcxx-module-interface.swift index e2ee6d2be71eb..f95694f45f59d 100644 --- a/test/Interop/Cxx/stdlib/libcxx-module-interface.swift +++ b/test/Interop/Cxx/stdlib/libcxx-module-interface.swift @@ -1,6 +1,6 @@ -// RUN: %target-swift-ide-test -print-module -module-to-print=std -source-filename=x -enable-experimental-cxx-interop -tools-directory=%llvm_obj_root/bin -module-cache-path %t | %FileCheck %s -check-prefix=CHECK-STD -// RUN: %target-swift-ide-test -print-module -module-to-print=std.iosfwd -source-filename=x -enable-experimental-cxx-interop -tools-directory=%llvm_obj_root/bin -module-cache-path %t | %FileCheck %s -check-prefix=CHECK-IOSFWD -// RUN: %target-swift-ide-test -print-module -module-to-print=std.string -source-filename=x -enable-experimental-cxx-interop -tools-directory=%llvm_obj_root/bin -module-cache-path %t | %FileCheck %s -check-prefix=CHECK-STRING +// RUN: %target-swift-ide-test -print-module -module-to-print=CxxStdlib -source-filename=x -enable-experimental-cxx-interop -tools-directory=%llvm_obj_root/bin -module-cache-path %t | %FileCheck %s -check-prefix=CHECK-STD +// RUN: %target-swift-ide-test -print-module -module-to-print=CxxStdlib.iosfwd -source-filename=x -enable-experimental-cxx-interop -tools-directory=%llvm_obj_root/bin -module-cache-path %t | %FileCheck %s -check-prefix=CHECK-IOSFWD +// RUN: %target-swift-ide-test -print-module -module-to-print=CxxStdlib.string -source-filename=x -enable-experimental-cxx-interop -tools-directory=%llvm_obj_root/bin -module-cache-path %t | %FileCheck %s -check-prefix=CHECK-STRING // This test is specific to libc++ and therefore only runs on Darwin platforms. // REQUIRES: OS=macosx || OS=ios diff --git a/test/Interop/Cxx/stdlib/libstdcxx-module-interface.swift b/test/Interop/Cxx/stdlib/libstdcxx-module-interface.swift index 1fa885f2c1646..047ca9127286e 100644 --- a/test/Interop/Cxx/stdlib/libstdcxx-module-interface.swift +++ b/test/Interop/Cxx/stdlib/libstdcxx-module-interface.swift @@ -1,5 +1,5 @@ // RUN: %empty-directory(%t) -// RUN: %target-swift-ide-test -print-module -module-to-print=std -source-filename=x -enable-experimental-cxx-interop -module-cache-path %t > %t/interface.swift +// RUN: %target-swift-ide-test -print-module -module-to-print=CxxStdlib -source-filename=x -enable-experimental-cxx-interop -module-cache-path %t > %t/interface.swift // RUN: %FileCheck %s -check-prefix=CHECK-STD < %t/interface.swift // RUN: %FileCheck %s -check-prefix=CHECK-SIZE-T < %t/interface.swift // RUN: %FileCheck %s -check-prefix=CHECK-TO-STRING < %t/interface.swift diff --git a/test/Interop/Cxx/stdlib/msvcprt-module-interface.swift b/test/Interop/Cxx/stdlib/msvcprt-module-interface.swift index c1522ba7525cf..aea5146b4a1b7 100644 --- a/test/Interop/Cxx/stdlib/msvcprt-module-interface.swift +++ b/test/Interop/Cxx/stdlib/msvcprt-module-interface.swift @@ -1,6 +1,6 @@ // RUN: %empty-directory(%t) -// RUN: %target-swift-ide-test -print-module -module-to-print std -source-filename none -enable-experimental-cxx-interop -module-cache-path %t | %FileCheck %s -check-prefix CHECK-STD -// RUN: %target-swift-ide-test -print-module -module-to-print=std.string -source-filename=x -enable-experimental-cxx-interop -module-cache-path %t | %FileCheck %s -check-prefix CHECK-STRING +// RUN: %target-swift-ide-test -print-module -module-to-print CxxStdlib -source-filename none -enable-experimental-cxx-interop -module-cache-path %t | %FileCheck %s -check-prefix CHECK-STD +// RUN: %target-swift-ide-test -print-module -module-to-print=CxxStdlib.string -source-filename=x -enable-experimental-cxx-interop -module-cache-path %t | %FileCheck %s -check-prefix CHECK-STRING // This test is specific to msvcprt and therefore only runs on Windows. // REQUIRES: OS=windows-msvc diff --git a/test/Interop/Cxx/stdlib/use-std-string.swift b/test/Interop/Cxx/stdlib/use-std-string.swift index e70c7bc578192..500737ac848a0 100644 --- a/test/Interop/Cxx/stdlib/use-std-string.swift +++ b/test/Interop/Cxx/stdlib/use-std-string.swift @@ -1,4 +1,5 @@ // RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop) +// RUN: %target-run-simple-swift(-D USE_CXXSTDLIB_SPELLING -I %S/Inputs -Xfrontend -enable-experimental-cxx-interop) // // REQUIRES: executable_test // @@ -8,11 +9,19 @@ import StdlibUnittest import StdString #if os(Linux) +#if USE_CXXSTDLIB_SPELLING +import CxxStdlib +#else import std -// FIXME: import std.string once libstdc++ is split into submodules. +#endif +// FIXME: import CxxStdlib.string once libstdc++ is split into submodules. +#else +#if USE_CXXSTDLIB_SPELLING +import CxxStdlib.string #else import std.string #endif +#endif var StdStringTestSuite = TestSuite("StdString")