Skip to content

Commit

Permalink
Fix assertion on !eq(?, 0)
Browse files Browse the repository at this point in the history
Instead of asserting, emit a proper error message
  • Loading branch information
dsandersllvm committed Feb 18, 2020
1 parent 9d37f5a commit 2c8ee53
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
8 changes: 7 additions & 1 deletion llvm/lib/TableGen/TGParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 9 additions & 0 deletions llvm/test/TableGen/eq-unset.td
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 2c8ee53

Please sign in to comment.