Skip to content

MLIR loc interpreted as pdl.attribute value #53030

Open
@henrytwo

Description

@henrytwo

Consider the following PDL pattern, where we have an attribute with a known type:

pdl.pattern : benefit(1)  {
  %0 = pdl.type : i32
  %1 = pdl.attribute : %0 loc("-":15:12)
  
  %2 = pdl.operation "C" {"Foo" = %1}
  pdl.rewrite {
    pdl.erase %2
  } 
}

As the custom PDL syntax is currently defined, the location will be inadvertently interpreted as the value for the attribute.

operation ::= `pdl.attribute` (`:` $type^)? ($value^)? attr-dict-with-keyword

This results in the following error when passed through mlir-opt on LLVM version 14.0.0:

<stdin>:3:8: error: 'pdl.attribute' op expected only one of [`type`, `value`] to be set
  %1 = pdl.attribute : %0 loc("-":15:12)
       ^
<stdin>:3:8: note: see current operation: %1 = "pdl.attribute"(%0) {value = loc("-":15:12)} : (!pdl.type) -> !pdl.attribute

The above MLIR originated from a mlir::Operation in C++ and was printed using the following flags (irrelevant locations omitted for brevity):

mlir::OpPrintingFlags().useLocalScope().enableDebugInfo()

This looks like a bug (or at least an issue with the op syntax), since this MLIR does not make it through a full round trip after being printed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions