[clang] Add wasm-opt warning (PR #100321)
Quentin Michaud via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 29 07:37:27 PDT 2024
https://github.com/mh4ck-Thales updated https://github.com/llvm/llvm-project/pull/100321
>From b812b9c2a7b92edf5dab739eadff0295c2a1f631 Mon Sep 17 00:00:00 2001
From: Quentin Michaud <quentin.michaud at thalesgroup.com>
Date: Wed, 24 Jul 2024 09:54:53 +0200
Subject: [PATCH 1/2] First draft of wasm-opt warning
---
clang/lib/Driver/ToolChains/WebAssembly.cpp | 3 +++
1 file changed, 3 insertions(+)
diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp b/clang/lib/Driver/ToolChains/WebAssembly.cpp
index 9aacda5fd5702f..dc49fde378a9a7 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -180,6 +180,9 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
if (WasmOptPath == "wasm-opt") {
WasmOptPath = {};
}
+ if (WasmOptPath.empty()) {
+ printf("warning: wasm-opt not found but was requested\n");
+ }
}
if (!WasmOptPath.empty()) {
>From a798b1fd7a7a6c7b782584021e5c32e52c3abffc Mon Sep 17 00:00:00 2001
From: Quentin Michaud <quentin.michaud at thalesgroup.com>
Date: Thu, 29 Aug 2024 16:31:48 +0200
Subject: [PATCH 2/2] Add errors and warnings for when wasm-opt is missing or
invoked but incompatible
---
clang/include/clang/Basic/DiagnosticDriverKinds.td | 8 ++++++++
clang/include/clang/Basic/DiagnosticGroups.td | 2 ++
clang/include/clang/Driver/Options.td | 1 +
clang/lib/Driver/ToolChains/WebAssembly.cpp | 14 +++++++++++++-
4 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index ba90742fbdaabc..2a862edf8788c8 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<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'">;
}
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td
index 28d315f63e5c47..fab11f47492db3 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 83cf753e824845..ba6e7ab9e11d06 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<m_Group>,
HelpText<"Enable the wasm-opt optimizer (default)">,
MarshallingInfoNegativeFlag<LangOpts<"NoWasmOpt">>;
+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 dc49fde378a9a7..e9820ce1d35995 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;
@@ -181,7 +188,12 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
WasmOptPath = {};
}
if (WasmOptPath.empty()) {
- printf("warning: wasm-opt not found but was requested\n");
+ 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);
+ }
}
}
More information about the cfe-commits
mailing list