Skip to content

Commit d1d1340

Browse files
committed
[clang] Ensure --print-runtime-dir exits
Before this PR, `clang --print-runtime-dir` used to report a non-existant directory if LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF. We now check if any of the known runtime directories exist before printing on stdout.
1 parent a819b0e commit d1d1340

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,10 +2230,14 @@ bool Driver::HandleImmediateArgs(Compilation &C) {
22302230
}
22312231

22322232
if (C.getArgs().hasArg(options::OPT_print_runtime_dir)) {
2233-
if (std::optional<std::string> RuntimePath = TC.getRuntimePath())
2234-
llvm::outs() << *RuntimePath << '\n';
2235-
else
2236-
llvm::outs() << TC.getCompilerRTPath() << '\n';
2233+
for (auto RuntimePath :
2234+
{TC.getRuntimePath(), std::make_optional(TC.getCompilerRTPath())}) {
2235+
if (RuntimePath && getVFS().exists(*RuntimePath)) {
2236+
llvm::outs() << *RuntimePath << '\n';
2237+
return false;
2238+
}
2239+
}
2240+
llvm::outs() << "(runtime dir is not present)" << '\n';
22372241
return false;
22382242
}
22392243

0 commit comments

Comments
 (0)