Skip to content

Commit 04c37bb

Browse files
committed
[test] Check that the C/C++ module maps are looked for in -resource-dir before -sdk, as changed in #74814
Also, dump the module map paths when `-Xfrontend -dump-clang-diagnostics` is passed in, both so we can check that manually and in these tests, and fix another Frontend test to be more specific now that this other output trips it up.
1 parent 965800f commit 04c37bb

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

lib/ClangImporter/ClangImporter.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -1155,7 +1155,7 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
11551155
llvm::interleave(
11561156
invocationArgs, [](StringRef arg) { llvm::errs() << arg; },
11571157
[] { llvm::errs() << "' '"; });
1158-
llvm::errs() << "'\n";
1158+
llvm::errs() << "'\n\n";
11591159
}
11601160

11611161
clang::CreateInvocationOptions CIOpts;
@@ -1260,11 +1260,24 @@ ClangImporter::create(ASTContext &ctx,
12601260
// Wrap Swift's FS to allow Clang to override the working directory
12611261
VFS = llvm::vfs::RedirectingFileSystem::create(
12621262
fileMapping.redirectedFiles, true, *ctx.SourceMgr.getFileSystem());
1263+
if (importerOpts.DumpClangDiagnostics) {
1264+
llvm::errs() << "clang importer redirected file mappings:\n";
1265+
for (const auto &mapping : fileMapping.redirectedFiles) {
1266+
llvm::errs() << " mapping real file '" << mapping.second
1267+
<< "' to virtual file '" << mapping.first << "'\n";
1268+
}
1269+
llvm::errs() << "\n";
1270+
}
12631271

12641272
if (!fileMapping.overridenFiles.empty()) {
12651273
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> overridenVFS =
12661274
new llvm::vfs::InMemoryFileSystem();
12671275
for (const auto &file : fileMapping.overridenFiles) {
1276+
if (importerOpts.DumpClangDiagnostics) {
1277+
llvm::errs() << "clang importer overriding file '" << file.first
1278+
<< "' with the following contents:\n";
1279+
llvm::errs() << file.second << "\n";
1280+
}
12681281
auto contents = ctx.Allocate<char>(file.second.size() + 1);
12691282
std::copy(file.second.begin(), file.second.end(), contents.begin());
12701283
// null terminate the buffer.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: mkdir -p %t/resources/linux/armv7 %t/sdk/usr/include %t/sdk/usr/lib/swift/linux/armv7
3+
// RUN: touch %t/sdk/usr/include/{inttypes,stdint,unistd}.h
4+
5+
// RUN: touch %t/resources/linux/armv7/{SwiftGlibc.h,glibc.modulemap}
6+
// RUN: touch %t/sdk/usr/lib/swift/linux/armv7/{SwiftGlibc.h,glibc.modulemap}
7+
// RUN: %swift %s -typecheck -parse-stdlib -dump-clang-diagnostics -target armv7-unknown-linux-gnueabihf -sdk %t/sdk -resource-dir %t/resources 2>&1 | %FileCheck -check-prefix=CHECK-LINUX %s
8+
9+
// RUN: cp %S/../../stdlib/public/Cxx/{cxxshim/libcxxshim.modulemap,libstdcxx/libstdcxx.h,libstdcxx/libstdcxx.modulemap} %t/resources/linux
10+
// RUN: %target-swift-frontend %s -typecheck -parse-stdlib -dump-clang-diagnostics -resource-dir %t/resources -cxx-interoperability-mode=default 2>&1 | %FileCheck -check-prefix=CHECK-CXX -check-prefix=CHECK-%target-os-CXX %s
11+
12+
// RUN: mkdir -p %t/resources/android/aarch64 %t/sdk/usr/lib/swift/android/aarch64
13+
// RUN: cp %S/../../stdlib/public/Platform/{SwiftAndroidNDK.h,SwiftBionic.h,android.modulemap} %t/resources/android/aarch64
14+
// RUN: cp %S/../../stdlib/public/Platform/{SwiftAndroidNDK.h,SwiftBionic.h,android.modulemap} %t/sdk/usr/lib/swift/android/aarch64
15+
// RUN: %swift %s -typecheck -parse-stdlib -dump-clang-diagnostics -target aarch64-unknown-linux-android -sdk %t/sdk -resource-dir %t/resources 2>&1 | %FileCheck -check-prefix=CHECK-ANDROID %s
16+
17+
// RUN: cp %S/../../stdlib/public/Cxx/cxxshim/libcxxshim.modulemap %t/resources/android
18+
// RUN: cp %S/../../stdlib/public/Cxx/cxxshim/libcxxshim.modulemap %t/sdk/usr/lib/swift/android
19+
// RUN: %swift %s -typecheck -parse-stdlib -dump-clang-diagnostics -target aarch64-unknown-linux-android -sdk %t/sdk -resource-dir %t/resources -cxx-interoperability-mode=default 2>&1 | %FileCheck -check-prefix=CHECK-ANDROID-CXX %s
20+
21+
// CHECK-LINUX: clang importer redirected file mappings:
22+
// CHECK-LINUX-NEXT: mapping real file '{{.*}}{{/|\\}}resources{{/|\\}}linux{{/|\\}}armv7{{/|\\}}glibc.modulemap' to virtual file '{{.*}}{{/|\\}}sdk{{/|\\}}usr{{/|\\}}include{{/|\\}}module.modulemap'
23+
// CHECK-LINUX-NEXT: mapping real file '{{.*}}{{/|\\}}resources{{/|\\}}linux{{/|\\}}armv7{{/|\\}}SwiftGlibc.h' to virtual file '{{.*}}{{/|\\}}sdk{{/|\\}}usr{{/|\\}}include{{/|\\}}SwiftGlibc.h'
24+
25+
// CHECK-CXX: clang importer redirected file mappings:
26+
// CHECK-linux-gnu-CXX: mapping real file '{{.*}}/resources/linux/libstdcxx.h' to virtual file '{{.*}}/usr/include/c++/{{.*}}/libstdcxx.h'
27+
// CHECK-linux-gnu-CXX: clang importer overriding file '{{.*}}/usr/include/c++/{{.*}}/module.modulemap' with the following contents:
28+
// CHECK-linux-gnu-CXX-NEXT: --- libstdcxx.modulemap ---
29+
// CHECK-linux-gnu-CXX: Currently libstdc++ does not have a module map. To work around
30+
// CHECK-linux-gnu-CXX-NEXT: this, Swift provides its own module map for libstdc++.
31+
// CHECK-linux-gnu-CXX: header "libstdcxx.h"
32+
// CHECK-linux-gnu-CXX: clang importer driver args: {{.*}}'-fmodule-map-file={{.*}}resources/linux/libcxxshim.modulemap'
33+
34+
// CHECK-ANDROID: clang importer redirected file mappings:
35+
// CHECK-ANDROID-NEXT: mapping real file '{{.*}}{{/|\\}}resources{{/|\\}}android{{/|\\}}aarch64{{/|\\}}android.modulemap' to virtual file '{{.*}}{{/|\\}}sdk{{/|\\}}usr{{/|\\}}include{{/|\\}}module.modulemap'
36+
// CHECK-ANDROID-NEXT: mapping real file '{{.*}}{{/|\\}}resources{{/|\\}}android{{/|\\}}aarch64{{/|\\}}SwiftAndroidNDK.h' to virtual file '{{.*}}{{/|\\}}sdk{{/|\\}}usr{{/|\\}}include{{/|\\}}SwiftAndroidNDK.h'
37+
// CHECK-ANDROID-NEXT: mapping real file '{{.*}}{{/|\\}}resources{{/|\\}}android{{/|\\}}aarch64{{/|\\}}SwiftBionic.h' to virtual file '{{.*}}{{/|\\}}sdk{{/|\\}}usr{{/|\\}}include{{/|\\}}SwiftBionic.h'
38+
39+
// CHECK-ANDROID-CXX: clang importer driver args: {{.*}}'-fmodule-map-file={{.*}}resources{{/|\\}}android{{/|\\}}libcxxshim.modulemap'

test/Frontend/embed-bitcode.ll

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
3636
; MARKER-CMD-NEXT: 00
3737

3838
; CHECK-COMPILER-NOT: argument unused
39-
; CHECK-COMPILER: clang
39+
; CHECK-COMPILER: bin{{/|\\}}clang
4040
; CHECK-COMPILER-SAME: -fembed-bitcode
4141
; CHECK-COMPILER-SAME: -target
4242
; CHECK-COMPILER-NOT: argument unused
4343
; CHECK-COMPILER: Fast Register Allocator
4444

4545
; CHECK-COMPILER-OPT-NOT: argument unused
46-
; CHECK-COMPILER-OPT: clang
46+
; CHECK-COMPILER-OPT: bin{{/|\\}}clang
4747
; CHECK-COMPILER-OPT-SAME: -fembed-bitcode
4848
; CHECK-COMPILER-OPT-SAME: -target
4949
; CHECK-COMPILER-OPT-SAME: -Os

0 commit comments

Comments
 (0)