Index: llvm/trunk/lib/TableGen/TGParser.cpp =================================================================== --- llvm/trunk/lib/TableGen/TGParser.cpp +++ llvm/trunk/lib/TableGen/TGParser.cpp @@ -1075,6 +1075,14 @@ return nullptr; } Type = MHSt->getType(); + if (isa(Type)) { + TypedInit *RHSt = dyn_cast(RHS); + if (!RHSt) { + TokError("could not get type of !foreach list elements"); + return nullptr; + } + Type = RHSt->getType()->getListTy(); + } break; } case tgtok::XSubst: { Index: llvm/trunk/test/TableGen/foreach.td =================================================================== --- llvm/trunk/test/TableGen/foreach.td +++ llvm/trunk/test/TableGen/foreach.td @@ -7,12 +7,18 @@ // CHECK: "NAME" // CHECK: Defs + +// CHECK: def DX { +// CHECK: list x = ["0", "1", "2"]; +// CHECK: } + // CHECK: Jr // CHECK: Sr // Variables for foreach class decls { string name; + int num; } def Decls : decls; @@ -37,3 +43,9 @@ def Juniors : C; def Smiths : D<["NAME", "Jane Smith"]>; def Unprocessed : D; + +class X a> { + list x = !foreach(Decls.num, a, !cast(Decls.num)); +} + +def DX : X<[0, 1, 2]>;