diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp --- a/llvm/lib/TableGen/TGParser.cpp +++ b/llvm/lib/TableGen/TGParser.cpp @@ -3524,8 +3524,8 @@ Substs.emplace_back(QualifiedNameOfImplicitName(MC), DefmName); - if (resolve(MC->Entries, Substs, CurMultiClass == nullptr, &NewEntries, - &SubClassLoc)) + if (resolve(MC->Entries, Substs, CurMultiClass == nullptr && Loops.empty(), + &NewEntries, &SubClassLoc)) return true; if (!consume(tgtok::comma)) diff --git a/llvm/test/TableGen/foreach-multiclass.td b/llvm/test/TableGen/foreach-multiclass.td --- a/llvm/test/TableGen/foreach-multiclass.td +++ b/llvm/test/TableGen/foreach-multiclass.td @@ -57,6 +57,9 @@ // CHECK: def F2_2_1 // CHECK-NOT: def F2_2_2 +// CHECK: def G0 +// CHECK: def anonymous_0 + multiclass A { foreach i = [0, 1] in { def NAME#i { @@ -116,3 +119,19 @@ defm F0 : F<[]>; defm F1 : F<[0]>; defm F2 : F<[0, 1, 2]>; + +class G { + list val = [10]; +} + +multiclass H { + foreach n = g.val in + def { + int val = n; + } +} + +def G0 : G; + +foreach g = [G0] in + defm : H;