Skip to content

Commit

Permalink
[TableGen] Fix instantiating multiclass in foreach
Browse files Browse the repository at this point in the history
If multiclass argument comes from loop varaible and argument is record type,
it will not recognize the type. This patch ensures that loop variables are
resolved correctly.

Differential Revision: https://reviews.llvm.org/D95308
  • Loading branch information
crabtw authored and Paul C. Anagnostopoulos committed Jan 29, 2021
1 parent d087d80 commit 5046c5b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions llvm/lib/TableGen/TGParser.cpp
Expand Up @@ -3524,8 +3524,8 @@ bool TGParser::ParseDefm(MultiClass *CurMultiClass) {

Substs.emplace_back(QualifiedNameOfImplicitName(MC), DefmName);

if (resolve(MC->Entries, Substs, CurMultiClass == nullptr, &NewEntries,
&SubClassLoc))
if (resolve(MC->Entries, Substs, !CurMultiClass && Loops.empty(),
&NewEntries, &SubClassLoc))
return true;

if (!consume(tgtok::comma))
Expand Down
20 changes: 20 additions & 0 deletions llvm/test/TableGen/foreach-multiclass.td
Expand Up @@ -57,6 +57,9 @@
// CHECK: def F2_2_1
// CHECK-NOT: def F2_2_2

// CHECK: def G0
// CHECK: def H0_G0_0

multiclass A<int x> {
foreach i = [0, 1] in {
def NAME#i {
Expand Down Expand Up @@ -116,3 +119,20 @@ multiclass F<list<int> lst> {
defm F0 : F<[]>;
defm F1 : F<[0]>;
defm F2 : F<[0, 1, 2]>;

// If multiclass argument comes from loop variable,
// and field of argument is placed at foreach statement,
// the record field must be resolved correctly.
class G {
list<int> val = [0];
}

multiclass H<G g> {
foreach n = g.val in
def _#g#_#n;
}

def G0 : G;

foreach g = [G0] in
defm H0 : H<g>;

0 comments on commit 5046c5b

Please sign in to comment.