From 8f1e2151b8e923345a18aa3025a7d074e134768b Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 2 Dec 2019 11:47:31 -0800 Subject: [PATCH] [WebAssembly] Find wasm-opt with GetProgramPath Instead of just searching for wasm-opt in PATH, use GetProgramPath, which checks the `COMPILER_PATH` environment variable, -B paths, and `PATH`. Differential Revision: https://reviews.llvm.org/D70780 --- clang/lib/Driver/ToolChains/WebAssembly.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp b/clang/lib/Driver/ToolChains/WebAssembly.cpp index 55b8259..1bb7c35 100644 --- a/clang/lib/Driver/ToolChains/WebAssembly.cpp +++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp @@ -92,10 +92,10 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA, C.addCommand(std::make_unique(JA, *this, Linker, CmdArgs, Inputs)); - // When optimizing, if wasm-opt is in the PATH, run wasm-opt. + // When optimizing, if wasm-opt is available, run it. if (Arg *A = Args.getLastArg(options::OPT_O_Group)) { - if (llvm::ErrorOr WasmOptPath = - llvm::sys::findProgramByName("wasm-opt")) { + auto WasmOptPath = getToolChain().GetProgramPath("wasm-opt"); + if (WasmOptPath != "wasm-opt") { StringRef OOpt = "s"; if (A->getOption().matches(options::OPT_O4) || A->getOption().matches(options::OPT_Ofast)) @@ -106,7 +106,7 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA, OOpt = A->getValue(); if (OOpt != "0") { - const char *WasmOpt = Args.MakeArgString(*WasmOptPath); + const char *WasmOpt = Args.MakeArgString(WasmOptPath); ArgStringList CmdArgs; CmdArgs.push_back(Output.getFilename()); CmdArgs.push_back(Args.MakeArgString(llvm::Twine("-O") + OOpt)); -- 2.7.4