diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index ba90742fbdaab..2a862edf8788c 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -826,4 +826,12 @@ def err_drv_triple_version_invalid : Error< def warn_missing_include_dirs : Warning< "no such include directory: '%0'">, InGroup, DefaultIgnore; + +def warn_wasm_opt_not_found : Warning< + "wasm-opt was not found, some optimizations were not applied">, + InGroup; +def err_wasm_opt_not_found_with_flag : Error< + "wasm-opt was explicitly requested, but was not found">; +def err_wasm_opt_requested_but_not_supported : Error< + "wasm-opt was explicitly requested, but is not supported with '%0'">; } diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 28d315f63e5c4..fab11f47492db 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/include/clang/Basic/DiagnosticGroups.td @@ -1520,6 +1520,8 @@ in addition with the pragmas or -fmax-tokens flag to get any warnings. def WebAssemblyExceptionSpec : DiagGroup<"wasm-exception-spec">; +def WebAssemblyOptimization : DiagGroup<"wasm-opt">; + def RTTI : DiagGroup<"rtti">; def OpenCLCoreFeaturesDiagGroup : DiagGroup<"pedantic-core-features">; diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 83cf753e82484..ba6e7ab9e11d0 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -8923,3 +8923,4 @@ def wasm_opt : Flag<["--"], "wasm-opt">, Group, HelpText<"Enable the wasm-opt optimizer (default)">, MarshallingInfoNegativeFlag>; +def Wwarn_wasm_opt_not_found : Flag<["-"], "Wwarn_wasm_opt_not_found">; diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp b/clang/lib/Driver/ToolChains/WebAssembly.cpp index 9aacda5fd5702..e9820ce1d3599 100644 --- a/clang/lib/Driver/ToolChains/WebAssembly.cpp +++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp @@ -9,6 +9,7 @@ #include "WebAssembly.h" #include "CommonArgs.h" #include "Gnu.h" +#include "clang/Basic/DiagnosticDriver.h" #include "clang/Basic/Version.h" #include "clang/Config/config.h" #include "clang/Driver/Compilation.h" @@ -20,6 +21,7 @@ #include "llvm/Support/Path.h" #include "llvm/Support/VirtualFileSystem.h" + using namespace clang::driver; using namespace clang::driver::tools; using namespace clang::driver::toolchains; @@ -172,6 +174,11 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA, bool RunWasmOpt = Args.hasFlag(options::OPT_wasm_opt, options::OPT_no_wasm_opt, WasmOptDefault); + if (TargetBuildsComponents(ToolChain.getTriple()) && + Args.hasFlag(options::OPT_wasm_opt, options::OPT_no_wasm_opt, false)) { + ToolChain.getDriver().Diag(diag::err_wasm_opt_requested_but_not_supported) + << ToolChain.getTriple().str(); + } // If wasm-opt is enabled and optimizations are happening look for the // `wasm-opt` program. If it's not found auto-disable it. std::string WasmOptPath; @@ -180,6 +187,14 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (WasmOptPath == "wasm-opt") { WasmOptPath = {}; } + if (WasmOptPath.empty()) { + if (Args.hasFlag(options::OPT_wasm_opt, options::OPT_no_wasm_opt, + false)) { + ToolChain.getDriver().Diag(diag::err_wasm_opt_not_found_with_flag); + } else { + ToolChain.getDriver().Diag(diag::warn_wasm_opt_not_found); + } + } } if (!WasmOptPath.empty()) {