Skip to content

Commit 2985c02

Browse files
committed
[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
1 parent b9af72b commit 2985c02

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ using namespace llvm;
3535

3636
#define DEBUG_TYPE "wasm-asm-parser"
3737

38+
static const char *getSubtargetFeatureName(uint64_t Val);
39+
3840
namespace {
3941

4042
/// WebAssemblyOperand - Instances of this class represent the operands in a
@@ -836,8 +838,9 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
836838
bool MatchingInlineAsm) override {
837839
MCInst Inst;
838840
Inst.setLoc(IDLoc);
839-
unsigned MatchResult =
840-
MatchInstructionImpl(Operands, Inst, ErrorInfo, MatchingInlineAsm);
841+
FeatureBitset MissingFeatures;
842+
unsigned MatchResult = MatchInstructionImpl(
843+
Operands, Inst, ErrorInfo, MissingFeatures, MatchingInlineAsm);
841844
switch (MatchResult) {
842845
case Match_Success: {
843846
ensureLocals(Out);
@@ -866,9 +869,17 @@ class WebAssemblyAsmParser final : public MCTargetAsmParser {
866869
}
867870
return false;
868871
}
869-
case Match_MissingFeature:
870-
return Parser.Error(
871-
IDLoc, "instruction requires a Wasm feature not currently enabled");
872+
case Match_MissingFeature: {
873+
auto NumMissing = MissingFeatures.count();
874+
assert(NumMissing > 0 && "Expected missing features");
875+
SmallString<128> Message;
876+
raw_svector_ostream OS(Message);
877+
OS << "instruction requires:";
878+
for (unsigned i = 0, e = MissingFeatures.size(); i != e; ++i)
879+
if (MissingFeatures.test(i))
880+
OS << ' ' << getSubtargetFeatureName(i);
881+
return Parser.Error(IDLoc, Message);
882+
}
872883
case Match_MnemonicFail:
873884
return Parser.Error(IDLoc, "invalid instruction");
874885
case Match_NearMisses:
@@ -932,5 +943,6 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeWebAssemblyAsmParser() {
932943
}
933944

934945
#define GET_REGISTER_MATCHER
946+
#define GET_SUBTARGET_FEATURE_NAME
935947
#define GET_MATCHER_IMPLEMENTATION
936948
#include "WebAssemblyGenAsmMatcher.inc"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# RUN: not llvm-mc -triple=wasm32-unknown-unknown < %s 2>&1 | FileCheck %s
2+
3+
# Check that missing features are named in the error message
4+
5+
# CHECK: error: instruction requires: simd128
6+
needs_simd:
7+
.functype needs_simd () -> (v128)
8+
i32.const 42
9+
i32x4.splat
10+
drop
11+
end_function

0 commit comments

Comments
 (0)