[Mlir-commits] [mlir] 9d10be7 - [mlir] std.call reference function return types in failure

Jacques Pienaar llvmlistbot at llvm.org
Thu Aug 5 19:52:07 PDT 2021


Author: Jacques Pienaar
Date: 2021-08-05T19:51:48-07:00
New Revision: 9d10be70a8289b50b1df32605516a0060854c91a

URL: https://github.com/llvm/llvm-project/commit/9d10be70a8289b50b1df32605516a0060854c91a
DIFF: https://github.com/llvm/llvm-project/commit/9d10be70a8289b50b1df32605516a0060854c91a.diff

LOG: [mlir] std.call reference function return types in failure

Makes it easier to see type mismatch from failure locally.

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

Added: 
    

Modified: 
    mlir/lib/Dialect/StandardOps/IR/Ops.cpp
    mlir/test/Dialect/Standard/invalid.mlir

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp
index 49c285b7fd63c..e9ec915cc8717 100644
--- a/mlir/lib/Dialect/StandardOps/IR/Ops.cpp
+++ b/mlir/lib/Dialect/StandardOps/IR/Ops.cpp
@@ -622,8 +622,12 @@ LogicalResult CallOp::verifySymbolUses(SymbolTableCollection &symbolTable) {
     return emitOpError("incorrect number of results for callee");
 
   for (unsigned i = 0, e = fnType.getNumResults(); i != e; ++i)
-    if (getResult(i).getType() != fnType.getResult(i))
-      return emitOpError("result type mismatch");
+    if (getResult(i).getType() != fnType.getResult(i)) {
+      auto diag = emitOpError("result type mismatch at index ") << i;
+      diag.attachNote() << "      op result types: " << getResultTypes();
+      diag.attachNote() << "function result types: " << fnType.getResults();
+      return diag;
+    }
 
   return success();
 }

diff  --git a/mlir/test/Dialect/Standard/invalid.mlir b/mlir/test/Dialect/Standard/invalid.mlir
index 169d187a43726..c45455b0d9695 100644
--- a/mlir/test/Dialect/Standard/invalid.mlir
+++ b/mlir/test/Dialect/Standard/invalid.mlir
@@ -69,3 +69,19 @@ func @complex_constant_two_
diff erent_element_types() {
   %0 = constant [1.0 : f32, -1.0 : f64] : complex<f64>
   return
 }
+
+// -----
+
+func @return_i32_f32() -> (i32, f32) {
+  %0 = constant 1 : i32
+  %1 = constant 1. : f32
+  return %0, %1 : i32, f32
+}
+
+func @call() {
+  // expected-error @+3 {{op result type mismatch at index 0}}
+  // expected-note @+2 {{op result types: 'f32', 'i32'}}
+  // expected-note @+1 {{function result types: 'i32', 'f32'}}
+  %0:2 = call @return_i32_f32() : () -> (f32, i32)
+  return
+}


        


More information about the Mlir-commits mailing list