Skip to content

Commit 0682015

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 8879ae5 commit 0682015

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1186,7 +1186,7 @@ std::optional<std::vector<std::string>> ClangImporter::getClangCC1Arguments(
11861186
llvm::interleave(
11871187
invocationArgs, [](StringRef arg) { llvm::errs() << arg; },
11881188
[] { llvm::errs() << "' '"; });
1189-
llvm::errs() << "'\n";
1189+
llvm::errs() << "'\n\n";
11901190
}
11911191

11921192
clang::CreateInvocationOptions CIOpts;
@@ -1291,11 +1291,24 @@ ClangImporter::create(ASTContext &ctx,
12911291
// Wrap Swift's FS to allow Clang to override the working directory
12921292
VFS = llvm::vfs::RedirectingFileSystem::create(
12931293
fileMapping.redirectedFiles, true, *ctx.SourceMgr.getFileSystem());
1294+
if (importerOpts.DumpClangDiagnostics) {
1295+
llvm::errs() << "clang importer redirected file mappings:\n";
1296+
for (const auto &mapping : fileMapping.redirectedFiles) {
1297+
llvm::errs() << " mapping real file '" << mapping.second
1298+
<< "' to virtual file '" << mapping.first << "'\n";
1299+
}
1300+
llvm::errs() << "\n";
1301+
}
12941302

12951303
if (!fileMapping.overridenFiles.empty()) {
12961304
llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> overridenVFS =
12971305
new llvm::vfs::InMemoryFileSystem();
12981306
for (const auto &file : fileMapping.overridenFiles) {
1307+
if (importerOpts.DumpClangDiagnostics) {
1308+
llvm::errs() << "clang importer overriding file '" << file.first
1309+
<< "' with the following contents:\n";
1310+
llvm::errs() << file.second << "\n";
1311+
}
12991312
auto contents = ctx.Allocate<char>(file.second.size() + 1);
13001313
std::copy(file.second.begin(), file.second.end(), contents.begin());
13011314
// null terminate the buffer.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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: if [ %target-os == "linux-gnu" ]; then %target-swift-frontend %s -typecheck -parse-stdlib -dump-clang-diagnostics -resource-dir %t/resources -cxx-interoperability-mode=default 2>&1 | %FileCheck -check-prefix=CHECK-LINUX-CXX %s; fi
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-LINUX-CXX: mapping real file '{{.*}}/resources/linux/libstdcxx.h' to virtual file '{{.*}}/usr/include/c++/{{.*}}/libstdcxx.h'
26+
// CHECK-LINUX-CXX: clang importer overriding file '{{.*}}/usr/include/c++/{{.*}}/module.modulemap' with the following contents:
27+
// CHECK-LINUX-CXX-NEXT: --- libstdcxx.modulemap ---
28+
// CHECK-LINUX-CXX: Currently libstdc++ does not have a module map. To work around
29+
// CHECK-LINUX-CXX-NEXT: this, Swift provides its own module map for libstdc++.
30+
// CHECK-LINUX-CXX: header "libstdcxx.h"
31+
// CHECK-LINUX-CXX: clang importer driver args: {{.*}}'-fmodule-map-file={{.*}}resources/linux/libcxxshim.modulemap'
32+
33+
// CHECK-ANDROID: clang importer redirected file mappings:
34+
// CHECK-ANDROID-NEXT: mapping real file '{{.*}}/resources/android/aarch64/android.modulemap' to virtual file '{{.*}}/sdk/usr/include/module.modulemap'
35+
// CHECK-ANDROID-NEXT: mapping real file '{{.*}}/resources/android/aarch64/SwiftAndroidNDK.h' to virtual file '{{.*}}/sdk/usr/include/SwiftAndroidNDK.h'
36+
// CHECK-ANDROID-NEXT: mapping real file '{{.*}}/resources/android/aarch64/SwiftBionic.h' to virtual file '{{.*}}/sdk/usr/include/SwiftBionic.h'
37+
38+
// CHECK-ANDROID-CXX: clang importer driver args: {{.*}}'-fmodule-map-file={{.*}}resources/android/libcxxshim.modulemap'

test/Frontend/embed-bitcode.ll

Lines changed: 2 additions & 2 deletions
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)