[llvm] [LLVM][MC][DecoderEmitter] Fail fatally if `Insn` and decoder table bitwidths mismatch (PR #156734)
Sergei Barannikov via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 3 15:00:51 PDT 2025
================
@@ -2108,9 +2121,19 @@ static DecodeStatus decodeInstruction(const uint8_t DecodeTable[], MCInst &MI,
if (HasCheckPredicate)
OS << " const FeatureBitset &Bits = STI.getFeatureBits();\n";
OS << " using namespace llvm::MCD;\n";
+ OS << " const uint8_t *Ptr = DecodeTable;\n";
+
+ if (SpecializeDecodersPerBitwidth) {
+ // Fail with a fatal error if decoder table's bitwidth does not match
+ // `InsnType` bitwidth.
+ OS << R"(
+ uint32_t BitWidth = decodeULEB128AndIncUnsafe(Ptr);
+ if (InsnBitWidth<InsnType> != BitWidth)
+ llvm_unreachable("Table and instruction bitwidth mismatch");
----------------
s-barannikov wrote:
I guess it is more or less the same as:
```suggestion
assert(InsnBitWidth<InsnType> == BitWidth &&
"Table and instruction bitwidth mismatch")`
```
(This will require `BitWidth` to be annotated with `[[maybe_unused]]`.)
https://github.com/llvm/llvm-project/pull/156734
More information about the llvm-commits
mailing list