Index: lib/TableGen/Record.cpp =================================================================== --- lib/TableGen/Record.cpp +++ lib/TableGen/Record.cpp @@ -709,6 +709,8 @@ return StringInit::get(LHSi->getAsString()); } else if (isa(getType())) { if (StringInit *Name = dyn_cast(LHS)) { + if (!CurRec && !IsFinal) + break; assert(CurRec && "NULL pointer"); Record *D; Index: test/TableGen/cast-multiclass.td =================================================================== --- /dev/null +++ test/TableGen/cast-multiclass.td @@ -0,0 +1,23 @@ +// RUN: llvm-tblgen %s | FileCheck %s + +class AClass { + bit Cond = C; +} + +def A0: AClass<0>; +def A1: AClass<1>; + +class BoolToList { + list ret = !if(Value, [1], []); +} + +multiclass P { + foreach i = BoolToList(AStr).Cond>.ret in + def SubDef; +} + +// CHECK-NOT: def XSubDef +defm X : P<"A0">; + +// CHECK: def YSubDef +defm Y : P<"A1">; \ No newline at end of file