Fix assertion on `!eq(?, 0)`
authorDaniel Sanders <daniel_l_sanders@apple.com>
Tue, 18 Feb 2020 21:12:28 +0000 (13:12 -0800)
committerDaniel Sanders <daniel_l_sanders@apple.com>
Tue, 18 Feb 2020 22:05:55 +0000 (14:05 -0800)
Instead of asserting, emit a proper error message

llvm/lib/TableGen/TGParser.cpp
llvm/test/TableGen/eq-unset.td [new file with mode: 0644]

index 9314523..3d77497 100644 (file)
@@ -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 (file)
index 0000000..57f06c3
--- /dev/null
@@ -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);
+}