Skip to content

Add wasm-opt warning #100321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -826,4 +826,12 @@ def err_drv_triple_version_invalid : Error<

def warn_missing_include_dirs : Warning<
"no such include directory: '%0'">, InGroup<MissingIncludeDirs>, DefaultIgnore;

def warn_wasm_opt_not_found : Warning<
"wasm-opt was not found, some optimizations were not applied">,
InGroup<WebAssemblyOptimization>;
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'">;
}
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticGroups.td
Original file line number Diff line number Diff line change
Expand Up @@ -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">;
Expand Down
1 change: 1 addition & 0 deletions clang/include/clang/Driver/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -8923,3 +8923,4 @@ def wasm_opt : Flag<["--"], "wasm-opt">,
Group<m_Group>,
HelpText<"Enable the wasm-opt optimizer (default)">,
MarshallingInfoNegativeFlag<LangOpts<"NoWasmOpt">>;
def Wwarn_wasm_opt_not_found : Flag<["-"], "Wwarn_wasm_opt_not_found">;
15 changes: 15 additions & 0 deletions clang/lib/Driver/ToolChains/WebAssembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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()) {
Expand Down
Loading