llvm / llvm/llvm-project

[mlir][PDL] ProcessDerivedPDLValue::processAsArg uses the removed Attribute::cast member

Open Beginner friendly
#218,047 2 comments 0 reactions 0 assignees View on GitHub
mlir
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

git version: [7196f93](https://github.com/llvm/llvm-project/commit/7196f931f212fc7c406066b2628a0ff4ea0ee344) (23.1.0-rc3)

system: `Ubuntu 24.04.3 LTS (Noble Numbat)`

`ProcessDerivedPDLValue::processAsArg` in [mlir/include/mlir/IR/PDLPatternMatch.h.inc](https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/IR/PDLPatternMatch.h.inc#L465) still calls the member-function cast that was removed from `Attribute`, `Type`, and `Value`:

```c++
static T processAsArg(BaseT baseValue) {
return baseValue.template cast(); // error: no member named 'cast'
}
```

This is a member of a class template, so it only fails when instantiated, which happens the moment a downstream project registers a native PDL constraint or rewrite whose parameter is a derived attribute, type, or op — precisely the case the surrounding doc comment advertises ("derived attributes like `IntegerAttr`, derived types like `IntegerType`, derived operations like `ModuleOp`"). It seems like nothing in-tree does this, so the error isn't seen.

Reproducer

```c++
pdlPattern.registerRewriteFunction(
"GetName",
[](PatternRewriter &, Operation *, StringAttr, TypeAttr) -> FailureOr {
return failure();
});
```

The fix is probably (worked in my environment).

```c++
static T processAsArg(BaseT baseValue) {
return llvm::cast(baseValue);
}
```

A test case added to [mlir/test/lib/Rewrite/TestPDLByteCode.cpp](https://github.com/llvm/llvm-project/blob/main/mlir/test/lib/Rewrite/TestPDLByteCode.cpp) using a derived attribute parameter could help this from regressing.

One such example that might work:

```c++
/// Native rewrite with a derived attribute parameter. Instantiates
/// ProcessDerivedPDLValue::processAsArg.
static StringAttr identityStringAttr(PatternRewriter &, StringAttr attr) {
return attr;
}
```

and then register it in `runOnOperation`:

```c++
pdlPattern.registerRewriteFunction("identity_str_attr", identityStringAttr);
```

Contributor guide

Open the contributing guide

Research direction

Start in mlir/include/mlir/IR/PDLPatternMatch.h.inc at ProcessDerivedPDLValue::processAsArg, then inspect native rewrite registrations in mlir/test/lib/Rewrite/TestPDLByteCode.cpp. Add a derived-attribute regression case, run the focused PDL bytecode test, and confirm the downstream-style registration instantiates successfully without the removed member call.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
84/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.