[all-commits] [llvm/llvm-project] 358412: [MLIR][ODS] Do not emit code when printing empty l...

crockeea via All-commits all-commits at lists.llvm.org
Wed Jun 10 14:09:27 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 358412632f118765935980f5f927764f11a2d800
      https://github.com/llvm/llvm-project/commit/358412632f118765935980f5f927764f11a2d800
  Author: crockeea <ecrockett0 at gmail.com>
  Date:   2026-06-10 (Wed, 10 Jun 2026)

  Changed paths:
    M mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp

  Log Message:
  -----------
  [MLIR][ODS] Do not emit code when printing empty lists in Type/Attr assembly printer (NFC) (#201174)

In TableGen's code generator, `DefFormat::genCommaSeparatedPrinter` can
emit code like
```
void FooType::print(::mlir::AsmPrinter &odsPrinter) const {
  ::mlir::Builder odsBuilder(getContext());
  odsPrinter << "<";
  {
    bool _firstPrinted = true;
  }
  odsPrinter << ">";
}
```

This results in unused variable warnings for `_firstPrinted` when
compiling the table-gen'd code:
```
warning: unused variable '_firstPrinted' [-Wunused-variable]
  158 |     bool _firstPrinted = true;
```

The solution to this is to not emit the `{ bool _firstPrinted = true; }`
block when list being printed is empty. This PR adds a guard around the
code that emits the `{ bool _firstPrinted = true; }`: it is now only
emitted if there are arguments to print. In this case, additional code
is emitted which uses `_firstPrinted`.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list