[PATCH] D98113: [Driver] Also search FilePaths for compiler-rt before falling back

Jessica Clarke via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Mar 6 09:18:15 PST 2021


jrtc27 updated this revision to Diff 328773.
jrtc27 added a comment.

... and another accidental change


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D98113/new/

https://reviews.llvm.org/D98113

Files:
  clang/lib/Driver/ToolChain.cpp
  clang/test/Driver/Inputs/baremetal_sysroot_with_compiler_rt/lib/libclang_rt.builtins-riscv64.a
  clang/test/Driver/baremetal-sysroot-with-compiler-rt.c


Index: clang/test/Driver/baremetal-sysroot-with-compiler-rt.c
===================================================================
--- /dev/null
+++ clang/test/Driver/baremetal-sysroot-with-compiler-rt.c
@@ -0,0 +1,6 @@
+// RUN: %clang -target riscv64 \
+// RUN:     --sysroot=%S/Inputs/baremetal_sysroot_with_compiler_rt \
+// RUN:     -rtlib=compiler-rt \
+// RUN:     -print-libgcc-file-name \
+// RUN:   | FileCheck %s
+// CHECK: {{.*[/\\]}}Inputs/baremetal_sysroot_with_compiler_rt{{[/\\]}}lib{{[/\\]}}libclang_rt.builtins-riscv64.a
Index: clang/lib/Driver/ToolChain.cpp
===================================================================
--- clang/lib/Driver/ToolChain.cpp
+++ clang/lib/Driver/ToolChain.cpp
@@ -459,12 +459,22 @@
   // Check for runtime files in the new layout without the architecture first.
   std::string CRTBasename =
       buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false);
-  for (const auto &LibPath : getLibraryPaths()) {
-    SmallString<128> P(LibPath);
-    llvm::sys::path::append(P, CRTBasename);
-    if (getVFS().exists(P))
-      return std::string(P.str());
-  }
+  auto SearchPaths = [&](const llvm::SmallVectorImpl<std::string> &Paths)
+      -> llvm::Optional<std::string> {
+    for (const auto &LibPath : Paths) {
+      SmallString<128> P(LibPath);
+      llvm::sys::path::append(P, CRTBasename);
+      if (getVFS().exists(P))
+        return std::string(P.str());
+    }
+    return None;
+  };
+
+  if (auto P = SearchPaths(getLibraryPaths()))
+    return *P;
+
+  if (auto P = SearchPaths(getFilePaths()))
+    return *P;
 
   // Fall back to the old expected compiler-rt name if the new one does not
   // exist.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98113.328773.patch
Type: text/x-patch
Size: 1680 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210306/19ed5c14/attachment-0001.bin>


More information about the cfe-commits mailing list