[Mlir-commits] [mlir] 0b42240 - [mlir][AsmPrinter] Gracefully handle empty symbol

Min-Yih Hsu llvmlistbot at llvm.org
Mon Jan 30 12:51:19 PST 2023


Author: Bruno Schmitt
Date: 2023-01-30T12:48:07-08:00
New Revision: 0b4224011aecb98facd406dc68dacecff40109e8

URL: https://github.com/llvm/llvm-project/commit/0b4224011aecb98facd406dc68dacecff40109e8
DIFF: https://github.com/llvm/llvm-project/commit/0b4224011aecb98facd406dc68dacecff40109e8.diff

LOG: [mlir][AsmPrinter] Gracefully handle empty symbol

The GenericOp printer should support malformed IR without crashing

GitHub issue #59529

Differential Revision: https://reviews.llvm.org/D142818

Added: 
    

Modified: 
    mlir/lib/IR/AsmPrinter.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/IR/AsmPrinter.cpp b/mlir/lib/IR/AsmPrinter.cpp
index af5cb6f354a2f..1ce617c0428fb 100644
--- a/mlir/lib/IR/AsmPrinter.cpp
+++ b/mlir/lib/IR/AsmPrinter.cpp
@@ -2042,7 +2042,10 @@ static void printKeywordOrString(StringRef keyword, raw_ostream &os) {
 /// represented as a string prefixed with '@'. The reference is surrounded with
 /// ""'s and escaped if it has any special or non-printable characters in it.
 static void printSymbolReference(StringRef symbolRef, raw_ostream &os) {
-  assert(!symbolRef.empty() && "expected valid symbol reference");
+  if (symbolRef.empty()) {
+    os << "@<<INVALID EMPTY SYMBOL>>";
+    return;
+  }
   os << '@';
   printKeywordOrString(symbolRef, os);
 }


        


More information about the Mlir-commits mailing list