Skip to content

[TableGen] llvm-tblgen crash error when using class as subroutine with recursion #91050

@kychendev

Description

@kychendev

When using class as subroutine with recursion, llvm-tblgen crashed in resolving references, as demonstrated by the following example.

class A <int a, int b, int s> {
  int n = !add(a, s, -1);
  list<string> ret =
      !if(!le(n, b),
          !listconcat([a#"-"#n],
                      A<!add(a, 1), b, s>.ret),
          []);  
}

def RecordA : A<0, 3, 2>;

Link to failed case: https://godbolt.org/z/5rTGo7TdK

The issue can be worked around by revising the class definition as follows. The only difference is substituting the use of variable "n" at line 4 with the expression "!add(a, s, -1)".

class A <int a, int b, int s> {
  int n = !add(a, s, -1);
  list<string> ret =
      !if(!le(!add(a, s, -1), b),
          !listconcat([a#"-"#n],
                      A<!add(a, 1), b, s>.ret),
          []);  
}

def RecordA : A<0, 3, 2>;

Link to working case: https://godbolt.org/z/zhYGo6Ea3

Metadata

Metadata

Assignees

Labels

crashPrefer [crash-on-valid] or [crash-on-invalid]tablegen

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions