[llvm] 38f153c - [TableGen] Fix null-pointer assert in RecordVal::setValue on failed cast (#195492)
via llvm-commits
llvm-commits at lists.llvm.org
Mon May 4 12:58:26 PDT 2026
Author: Prerona Chaudhuri
Date: 2026-05-04T12:58:21-07:00
New Revision: 38f153c7a7f1dd060d3afabc05f0fcb0585a10cb
URL: https://github.com/llvm/llvm-project/commit/38f153c7a7f1dd060d3afabc05f0fcb0585a10cb
DIFF: https://github.com/llvm/llvm-project/commit/38f153c7a7f1dd060d3afabc05f0fcb0585a10cb.diff
LOG: [TableGen] Fix null-pointer assert in RecordVal::setValue on failed cast (#195492)
When setValue's getCastTo failed, Value was overwritten with nullptr
instead of being left untouched.
The "no value set" sentinel is UnsetInit, not nullptr, so a downstream
RecordResolver::resolve that called isa<UnsetInit>(RV->getValue()) would
assert on the null pointer when a later def tried to resolve an
expression referring to that field.
Compute the cast into a local and only commit to Value on success, so a
type-incompatible override (e.g. redeclaring an int field as string in a
subclass) reports the existing "is incompatible" error and exits cleanly
instead of aborting.
Fixes issue : https://github.com/llvm/llvm-project/issues/184879
Assisted by Claude.
Added:
llvm/test/TableGen/incompatible-field-override.td
Modified:
llvm/lib/TableGen/Record.cpp
Removed:
################################################################################
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index 4e931209e3e7c..3395d2dd10a1b 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -2891,10 +2891,11 @@ bool RecordVal::setValue(const Init *V) {
return false;
}
- Value = V->getCastTo(getType());
- if (!Value)
+ const Init *NewValue = V->getCastTo(getType());
+ if (!NewValue)
return true;
+ Value = NewValue;
assert(!isa<TypedInit>(Value) ||
cast<TypedInit>(Value)->getType()->typeIsA(getType()));
if (const auto *BTy = dyn_cast<BitsRecTy>(getType())) {
diff --git a/llvm/test/TableGen/incompatible-field-override.td b/llvm/test/TableGen/incompatible-field-override.td
new file mode 100644
index 0000000000000..7d66e0411a5b8
--- /dev/null
+++ b/llvm/test/TableGen/incompatible-field-override.td
@@ -0,0 +1,18 @@
+// RUN: not llvm-tblgen %s 2>&1 | FileCheck %s
+
+// Redeclaring a field with an incompatible type used to leave the field's
+// Value as nullptr, causing an isa<UnsetInit>(nullptr) assert when a later
+// def tried to resolve an expression referring to that field.
+
+class X {
+ int F = 0;
+ int D = !add(F, 1);
+}
+
+// CHECK: error: Field 'F' of type 'int' is incompatible with value '"0"' of type 'string'
+// CHECK-NOT: Assertion `Val && "isa<> used on a null pointer"'
+class Y : X {
+ string F = "0";
+}
+
+def y : Y;
More information about the llvm-commits
mailing list