[Mlir-commits] [mlir] [mlir] Fix conflict of user defined reserved functions with internal prototypes (PR #123378)

Christian Ulmann llvmlistbot at llvm.org
Fri Jan 24 01:58:25 PST 2025


================
@@ -1546,24 +1546,32 @@ class VectorPrintOpConversion : public ConvertOpToLLVMPattern<vector::PrintOp> {
 
     auto punct = printOp.getPunctuation();
     if (auto stringLiteral = printOp.getStringLiteral()) {
-      LLVM::createPrintStrCall(rewriter, loc, parent, "vector_print_str",
-                               *stringLiteral, *getTypeConverter(),
-                               /*addNewline=*/false);
+      if (LLVM::createPrintStrCall(rewriter, loc, parent, "vector_print_str",
+                                   *stringLiteral, *getTypeConverter(),
+                                   /*addNewline=*/false)
+              .failed()) {
+        return failure();
+      }
     } else if (punct != PrintPunctuation::NoPunctuation) {
-      emitCall(rewriter, printOp->getLoc(), [&] {
-        switch (punct) {
-        case PrintPunctuation::Close:
-          return LLVM::lookupOrCreatePrintCloseFn(parent);
-        case PrintPunctuation::Open:
-          return LLVM::lookupOrCreatePrintOpenFn(parent);
-        case PrintPunctuation::Comma:
-          return LLVM::lookupOrCreatePrintCommaFn(parent);
-        case PrintPunctuation::NewLine:
-          return LLVM::lookupOrCreatePrintNewlineFn(parent);
-        default:
-          llvm_unreachable("unexpected punctuation");
-        }
-      }());
+      if (auto op = [&] -> FailureOr<LLVM::LLVMFuncOp> {
+            switch (punct) {
+            case PrintPunctuation::Close:
+              return LLVM::lookupOrCreatePrintCloseFn(parent);
+            case PrintPunctuation::Open:
+              return LLVM::lookupOrCreatePrintOpenFn(parent);
+            case PrintPunctuation::Comma:
+              return LLVM::lookupOrCreatePrintCommaFn(parent);
+            case PrintPunctuation::NewLine:
+              return LLVM::lookupOrCreatePrintNewlineFn(parent);
+            default:
+              llvm_unreachable("unexpected punctuation");
+            }
+          }();
+          succeeded(op))
----------------
Dinistro wrote:

Nit: As before, I would not wrap this into the if's condition. This is somewhat hard to read.

https://github.com/llvm/llvm-project/pull/123378


More information about the Mlir-commits mailing list