[llvm] 2985c02 - [WebAssembly][AsmParser] Name missing features in error message
Thomas Lively via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 11 17:26:24 PDT 2020
Author: Thomas Lively
Date: 2020-08-11T17:26:14-07:00
New Revision: 2985c02f798ba8248a9168a9f33a74d90c0c5445
URL: https://github.com/llvm/llvm-project/commit/2985c02f798ba8248a9168a9f33a74d90c0c5445
DIFF: https://github.com/llvm/llvm-project/commit/2985c02f798ba8248a9168a9f33a74d90c0c5445.diff
LOG: [WebAssembly][AsmParser] Name missing features in error message
Rather than just saying that some feature is missing, report the exact
features to make the error message more useful and actionable.
Differential Revision: https://reviews.llvm.org/D85795
Added:
llvm/test/MC/WebAssembly/missing-features.s
Modified:
llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
index 2fb7ea63e0c5..dcaab8a8af0d 100644
--- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -35,6 +35,8 @@ using namespace llvm;
#define DEBUG_TYPE "wasm-asm-parser"
+static const char *getSubtargetFeatureName(uint64_t Val);
+
namespace {
/// WebAssemblyOperand - Instances of this class represent the operands in a
@@ -836,8 +838,9 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
bool MatchingInlineAsm) override {
MCInst Inst;
Inst.setLoc(IDLoc);
- unsigned MatchResult =
- MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm);
+ FeatureBitset MissingFeatures;
+ unsigned MatchResult = MatchInstructionImpl(
+ Operands, Inst, ErrorInfo, MissingFeatures, MatchingInlineAsm);
switch (MatchResult) {
case Match_Success: {
ensureLocals(Out);
@@ -866,9 +869,17 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
}
return false;
}
- case Match_MissingFeature:
- return Parser.Error(
- IDLoc, "instruction requires a Wasm feature not currently enabled");
+ case Match_MissingFeature: {
+ auto NumMissing = MissingFeatures.count();
+ assert(NumMissing > 0 && "Expected missing features");
+ SmallString<128> Message;
+ raw_svector_ostream OS(Message);
+ OS << "instruction requires:";
+ for (unsigned i = 0, e = MissingFeatures.size(); i != e; ++i)
+ if (MissingFeatures.test(i))
+ OS << ' ' << getSubtargetFeatureName(i);
+ return Parser.Error(IDLoc, Message);
+ }
case Match_MnemonicFail:
return Parser.Error(IDLoc, "invalid instruction");
case Match_NearMisses:
@@ -932,5 +943,6 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeWebAssemblyAsmParser() {
}
#define GET_REGISTER_MATCHER
+#define GET_SUBTARGET_FEATURE_NAME
#define GET_MATCHER_IMPLEMENTATION
#include "WebAssemblyGenAsmMatcher.inc"
diff --git a/llvm/test/MC/WebAssembly/missing-features.s b/llvm/test/MC/WebAssembly/missing-features.s
new file mode 100644
index 000000000000..77ac4676ee0f
--- /dev/null
+++ b/llvm/test/MC/WebAssembly/missing-features.s
@@ -0,0 +1,11 @@
+# RUN: not llvm-mc -triple=wasm32-unknown-unknown < %s 2>&1 | FileCheck %s
+
+# Check that missing features are named in the error message
+
+# CHECK: error: instruction requires: simd128
+needs_simd:
+ .functype needs_simd () -> (v128)
+ i32.const 42
+ i32x4.splat
+ drop
+ end_function
More information about the llvm-commits
mailing list