-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
base: main
Are you sure you want to change the base?
Add wasm-opt warning #100321
Conversation
If wasm-opt is explicitly enabled via a flag, then I think it would make sense for this to be an error rather than a warning. Otherwise though if no default behavior was indicated then I would personally fear the churn of this change as most developers I know of on Personally I think that |
I'm not sure what is the problem with
The solution to this is just to add I agree that In the longer term, it would be nice to see if we can package and distribute |
Personally I don't find it to be a great user experience when a tool warns by default in default configration. This means that any user using wasi-sdk, for example, would by default with no other action taken receive warnings. That's annoying and misleading to end users because |
6a74d3a
to
a798b1f
Compare
You can test this locally with the following command:git-clang-format --diff 73ef397fcba35b7b4239c00bf3e0b4e689ca0add a798b1fd7a7a6c7b782584021e5c32e52c3abffc --extensions cpp -- clang/lib/Driver/ToolChains/WebAssembly.cpp View the diff from clang-format here.diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp b/clang/lib/Driver/ToolChains/WebAssembly.cpp
index e9820ce1d3..1fc74d28ab 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -21,7 +21,6 @@
#include "llvm/Support/Path.h"
#include "llvm/Support/VirtualFileSystem.h"
-
using namespace clang::driver;
using namespace clang::driver::tools;
using namespace clang::driver::toolchains;
|
I implemented a proposition on how to proceed for correctly informing users of wasm-opt problems:
We can discuss and change this, especially for the warning "by default" that is controversial. I think that a warning is the way to go if we want to leave wasm-opt enabled as a default, otherwise people with different tooling end up with vastly differing results without knowing why, but the point of @alexcrichton on the annoyance of having a warning is relevant. Another solution could be to just print a message without using warnings? Is there a mechanism in LLVM for printing info notes? |
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: Quentin Michaud (mh4ck-Thales) ChangesAdd a warning when I'm using #77148 as reference on how to add a new warning but please tell me if you can help in implementing this. Also I'm not sure in which warning group include this, at first glance none seem relevant for this specific problem. Regarding #98373 another warning might be relevant if people target WASIp2+ and try to use wasm-opt explicitly. This can be grouped in one warning "wasm-opt not available in this context" or separated in 2 for clearer error messages. WDYT? CC @sunfishcode @sbc100 @alexcrichton Full diff: https://github.com/llvm/llvm-project/pull/100321.diff 4 Files Affected:
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 9aacda5fd5702f..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;
@@ -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()) {
|
I can see how the current state of the world is resulting in this PR, but at least personally I continue to feel that a warning should not be emitted if no flags are passed and The other part of it is that personally I often specifically don't want |
Add a warning when
wasm-opt
is requested with a flag (#95208) but is not found in the path.I'm using #77148 as reference on how to add a new warning but please tell me if you can help in implementing this. Also I'm not sure in which warning group include this, at first glance none seem relevant for this specific problem.
Regarding #98373 another warning might be relevant if people target WASIp2+ and try to use wasm-opt explicitly. This can be grouped in one warning "wasm-opt not available in this context" or separated in 2 for clearer error messages. WDYT?
CC @sunfishcode @sbc100 @alexcrichton