[llvm] 2c8ee53 - Fix assertion on `!eq(?, 0)`
Daniel Sanders via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 18 14:06:09 PST 2020
Author: Daniel Sanders
Date: 2020-02-18T14:05:55-08:00
New Revision: 2c8ee5329bb1ff44ac5d827e3767b2e6ebdaf806
URL: https://github.com/llvm/llvm-project/commit/2c8ee5329bb1ff44ac5d827e3767b2e6ebdaf806
DIFF: https://github.com/llvm/llvm-project/commit/2c8ee5329bb1ff44ac5d827e3767b2e6ebdaf806.diff
LOG: Fix assertion on `!eq(?, 0)`
Instead of asserting, emit a proper error message
Added:
llvm/test/TableGen/eq-unset.td
Modified:
llvm/lib/TableGen/TGParser.cpp
Removed:
################################################################################
diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index 9314523c501a..3d774979eb5f 100644
--- a/llvm/lib/TableGen/TGParser.cpp
+++ b/llvm/lib/TableGen/TGParser.cpp
@@ -1180,7 +1180,13 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
InitList.push_back(ParseValue(CurRec, ArgType));
if (!InitList.back()) return nullptr;
- RecTy *ListType = cast<TypedInit>(InitList.back())->getType();
+ TypedInit *InitListBack = dyn_cast<TypedInit>(InitList.back());
+ if (!InitListBack) {
+ Error(OpLoc, Twine("expected value to be a typed value, got '" +
+ InitList.back()->getAsString() + "'"));
+ return nullptr;
+ }
+ RecTy *ListType = InitListBack->getType();
if (!ArgType) {
ArgType = ListType;
diff --git a/llvm/test/TableGen/eq-unset.td b/llvm/test/TableGen/eq-unset.td
new file mode 100644
index 000000000000..57f06c3a8a92
--- /dev/null
+++ b/llvm/test/TableGen/eq-unset.td
@@ -0,0 +1,9 @@
+// RUN: not llvm-tblgen %s 2>&1 | FileCheck %s
+
+// CHECK: error: expected value to be a typed value, got '?'
+
+def Z1 {
+ // This one caused an assertion because the value was an UnsetInit
+ // and !eq() can only accept TypedInit's.
+ bit D = !if(!eq(?, 0), 1, 0);
+}
More information about the llvm-commits
mailing list