Skip to content

Commit a798b1f

Browse files
committed
Add errors and warnings for when wasm-opt is missing or invoked but incompatible
1 parent b812b9c commit a798b1f

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,4 +826,12 @@ def err_drv_triple_version_invalid : Error<
826826

827827
def warn_missing_include_dirs : Warning<
828828
"no such include directory: '%0'">, InGroup<MissingIncludeDirs>, DefaultIgnore;
829+
830+
def warn_wasm_opt_not_found : Warning<
831+
"wasm-opt was not found, some optimizations were not applied">,
832+
InGroup<WebAssemblyOptimization>;
833+
def err_wasm_opt_not_found_with_flag : Error<
834+
"wasm-opt was explicitly requested, but was not found">;
835+
def err_wasm_opt_requested_but_not_supported : Error<
836+
"wasm-opt was explicitly requested, but is not supported with '%0'">;
829837
}

clang/include/clang/Basic/DiagnosticGroups.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1520,6 +1520,8 @@ in addition with the pragmas or -fmax-tokens flag to get any warnings.
15201520

15211521
def WebAssemblyExceptionSpec : DiagGroup<"wasm-exception-spec">;
15221522

1523+
def WebAssemblyOptimization : DiagGroup<"wasm-opt">;
1524+
15231525
def RTTI : DiagGroup<"rtti">;
15241526

15251527
def OpenCLCoreFeaturesDiagGroup : DiagGroup<"pedantic-core-features">;

clang/include/clang/Driver/Options.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8923,3 +8923,4 @@ def wasm_opt : Flag<["--"], "wasm-opt">,
89238923
Group<m_Group>,
89248924
HelpText<"Enable the wasm-opt optimizer (default)">,
89258925
MarshallingInfoNegativeFlag<LangOpts<"NoWasmOpt">>;
8926+
def Wwarn_wasm_opt_not_found : Flag<["-"], "Wwarn_wasm_opt_not_found">;

clang/lib/Driver/ToolChains/WebAssembly.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "WebAssembly.h"
1010
#include "CommonArgs.h"
1111
#include "Gnu.h"
12+
#include "clang/Basic/DiagnosticDriver.h"
1213
#include "clang/Basic/Version.h"
1314
#include "clang/Config/config.h"
1415
#include "clang/Driver/Compilation.h"
@@ -20,6 +21,7 @@
2021
#include "llvm/Support/Path.h"
2122
#include "llvm/Support/VirtualFileSystem.h"
2223

24+
2325
using namespace clang::driver;
2426
using namespace clang::driver::tools;
2527
using namespace clang::driver::toolchains;
@@ -172,6 +174,11 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
172174
bool RunWasmOpt = Args.hasFlag(options::OPT_wasm_opt,
173175
options::OPT_no_wasm_opt, WasmOptDefault);
174176

177+
if (TargetBuildsComponents(ToolChain.getTriple()) &&
178+
Args.hasFlag(options::OPT_wasm_opt, options::OPT_no_wasm_opt, false)) {
179+
ToolChain.getDriver().Diag(diag::err_wasm_opt_requested_but_not_supported)
180+
<< ToolChain.getTriple().str();
181+
}
175182
// If wasm-opt is enabled and optimizations are happening look for the
176183
// `wasm-opt` program. If it's not found auto-disable it.
177184
std::string WasmOptPath;
@@ -181,7 +188,12 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
181188
WasmOptPath = {};
182189
}
183190
if (WasmOptPath.empty()) {
184-
printf("warning: wasm-opt not found but was requested\n");
191+
if (Args.hasFlag(options::OPT_wasm_opt, options::OPT_no_wasm_opt,
192+
false)) {
193+
ToolChain.getDriver().Diag(diag::err_wasm_opt_not_found_with_flag);
194+
} else {
195+
ToolChain.getDriver().Diag(diag::warn_wasm_opt_not_found);
196+
}
185197
}
186198
}
187199

0 commit comments

Comments
 (0)