diff options
-rw-r--r-- | llvm/lib/TableGen/Record.cpp | 2 | ||||
-rw-r--r-- | llvm/test/TableGen/cast-multiclass.td | 23 |
2 files changed, 25 insertions, 0 deletions
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp index 0aa0944aeef..cf1685a2e8c 100644 --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -709,6 +709,8 @@ Init *UnOpInit::Fold(Record *CurRec, bool IsFinal) const { return StringInit::get(LHSi->getAsString()); } else if (isa<RecordRecTy>(getType())) { if (StringInit *Name = dyn_cast<StringInit>(LHS)) { + if (!CurRec && !IsFinal) + break; assert(CurRec && "NULL pointer"); Record *D; diff --git a/llvm/test/TableGen/cast-multiclass.td b/llvm/test/TableGen/cast-multiclass.td new file mode 100644 index 00000000000..7c8ed5f1f04 --- /dev/null +++ b/llvm/test/TableGen/cast-multiclass.td @@ -0,0 +1,23 @@ +// RUN: llvm-tblgen %s | FileCheck %s + +class AClass<bit C> { + bit Cond = C; +} + +def A0: AClass<0>; +def A1: AClass<1>; + +class BoolToList<bit Value> { + list<int> ret = !if(Value, [1]<int>, []<int>); +} + +multiclass P<string AStr> { + foreach i = BoolToList<!cast<AClass>(AStr).Cond>.ret in + def SubDef; +} + +// CHECK-NOT: def XSubDef +defm X : P<"A0">; + +// CHECK: def YSubDef +defm Y : P<"A1">; |