[all-commits] [llvm/llvm-project] 964997: [mlir][core] Fix ValueRange printing in AsmPrinter

Ahmed Harmouche via All-commits all-commits at lists.llvm.org
Mon Feb 27 14:54:33 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 964997a143cfa0356d1cd21eb3e6d2170c975c38
      https://github.com/llvm/llvm-project/commit/964997a143cfa0356d1cd21eb3e6d2170c975c38
  Author: wpmed92 <ahmedharmouche92 at gmail.com>
  Date:   2023-02-27 (Mon, 27 Feb 2023)

  Changed paths:
    M mlir/include/mlir/IR/OpImplementation.h

  Log Message:
  -----------
  [mlir][core] Fix ValueRange printing in AsmPrinter

The ValueRange printing behaviour of `OpAsmPrinter` and `AsmPrinter` is different, as reported [[ https://github.com/llvm/llvm-project/issues/59334 | here ]]

```
static void testPrint(AsmPrinter &p, Operation *op, ValueRange operands) {
  p << '(' << operands << ')';
}
```
Although the base `AsmPrinter` is passed as the first parameter (and not `OpAsmPrinter`), the code compiles fine. However, instead of the SSA values, the types for the operands will be printed. This is a violation of the Liskov Substitution Principle.
The desired behaviour would be that the above code does not compile. The reason it compiles, is that for the above code, the `TypeRange` version will be selected for the `<<` operator, since `ValueRange` is implicitly converted to `TypeRange`:
```
template <typename AsmPrinterT>
inline std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value,
                        AsmPrinterT &>
operator<<(AsmPrinterT &p, const TypeRange &types) {
  llvm::interleaveComma(types, p);
  return p;
}
```




More information about the All-commits mailing list