[PATCH] D70780: [WebAssembly] Find wasm-opt with GetProgramPath

Dan Gohman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 27 06:09:07 PST 2019


sunfish created this revision.
sunfish added reviewers: dschuff, ilya-biryukov.
Herald added subscribers: cfe-commits, aheejin, jgravelle-google, sbc100.
Herald added a project: clang.

Instead of just searching for wasm-opt in PATH, use `GetProgramPath`, which checks the `COMPILER_PATH` environment variable, `-B` paths, and `PATH.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D70780

Files:
  clang/lib/Driver/ToolChains/WebAssembly.cpp


Index: clang/lib/Driver/ToolChains/WebAssembly.cpp
===================================================================
--- clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -92,10 +92,10 @@
 
   C.addCommand(std::make_unique<Command>(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<std::string> 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 @@
         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));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70780.231236.patch
Type: text/x-patch
Size: 1211 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20191127/ed1f81a8/attachment.bin>


More information about the cfe-commits mailing list