[clang] [clang] Ensure `--print-runtime-dir` path exists (PR #102834)

via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 11 16:09:55 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Alexandre Ganea (aganea)

<details>
<summary>Changes</summary>

Before this PR, `clang --print-runtime-dir` used to report a non-existent directory if `LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF`.

We now check if any of the known runtime directories exist before printing on stdout. If it doesn't, we print `(runtime dir is not present)`.

---
Full diff: https://github.com/llvm/llvm-project/pull/102834.diff


1 Files Affected:

- (modified) clang/lib/Driver/Driver.cpp (+8-4) 


``````````diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index f4e909b79389bc..4c8cd36dd118ee 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -2230,10 +2230,14 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
   }
 
   if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
-    if (std::optional<std::string> RuntimePath = TC.getRuntimePath())
-      llvm::outs() << *RuntimePath << '\n';
-    else
-      llvm::outs() << TC.getCompilerRTPath() << '\n';
+    for (auto RuntimePath :
+         {TC.getRuntimePath(), std::make_optional(TC.getCompilerRTPath())}) {
+      if (RuntimePath && getVFS().exists(*RuntimePath)) {
+        llvm::outs() << *RuntimePath << '\n';
+        return false;
+      }
+    }
+    llvm::outs() << "(runtime dir is not present)" << '\n';
     return false;
   }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/102834


More information about the cfe-commits mailing list