This is an archive of the discontinued LLVM Phabricator instance.

Make the AsmPrinter print "<null type>" instead of crashing on null types
ClosedPublic

Authored by mehdi_amini on Apr 4 2020, 8:03 PM.

Details

Summary

Even if this indicates in general a problem at call sites, the printer
is used for debugging and avoiding crashing is friendlier for example
when used in diagnostics or other printer.

Diff Detail

Event Timeline

mehdi_amini created this revision.Apr 4 2020, 8:03 PM
Herald added 1 blocking reviewer(s): rriddle. · View Herald TranscriptApr 4 2020, 8:03 PM
Herald added a project: Restricted Project. · View Herald Transcript
rriddle accepted this revision.Apr 4 2020, 8:14 PM
This revision is now accepted and ready to land.Apr 4 2020, 8:14 PM
bondhugula accepted this revision.Apr 4 2020, 8:36 PM
bondhugula added a subscriber: bondhugula.
bondhugula added inline comments.
mlir/lib/IR/AsmPrinter.cpp
1494

This change is very welcome, thanks! It would be good keep the message format consistent though - there are other places in the ASM printer that handle such null structures. Can we make the casing and angular brackets uniform? (changing to your format sounds good).

if (!value) {
  stream << "<<NULL>>";
  return;
}
if (!attr) {
  os << "<<NULL ATTRIBUTE>>";
  return;
}
void AffineExpr::print(raw_ostream &os) const {
  if (expr == nullptr) {
    os << "null affine expr";
    return;
  }
void AffineExpr::dump() const {
  print(llvm::errs());
  llvm::errs() << "\n";
}

void AffineMap::print(raw_ostream &os) const {
  if (map == nullptr) {
    os << "null affine map";
    return;
  }
  ModulePrinter(os).printAffineMap(*this);
}

Update format to <<NULL TYPE>> for consistency with attributes

This revision was automatically updated to reflect the committed changes.