[mlir] fix crash when call a function decl
authorXiang Li <python3kgae@outlook.com>
Wed, 25 Jan 2023 15:26:01 +0000 (10:26 -0500)
committerXiang Li <python3kgae@outlook.com>
Wed, 25 Jan 2023 16:06:13 +0000 (11:06 -0500)
Check region before use it.
Fixes #60215  https://github.com/llvm/llvm-project/issues/60215

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

mlir/lib/Analysis/DataFlow/SparseAnalysis.cpp
mlir/test/Analysis/DataFlow/test-written-to.mlir

index 04d4738..478ff6d 100644 (file)
@@ -414,7 +414,7 @@ void AbstractSparseBackwardDataFlowAnalysis::visitOperation(Operation *op) {
     Operation *callableOp = call.resolveCallable(&symbolTable);
     if (auto callable = dyn_cast_or_null<CallableOpInterface>(callableOp)) {
       Region *region = callable.getCallableRegion();
-      if (!region->empty()) {
+      if (region && !region->empty()) {
         Block &block = region->front();
         for (auto [blockArg, operand] :
              llvm::zip(block.getArguments(), operandLattices)) {
index 09c9212..11a9f03 100644 (file)
@@ -246,3 +246,17 @@ func.func @test_switch(%arg0 : index, %m0: memref<i32>) {
   memref.store %1, %m0[] {tag_name = "b"} : memref<i32>
   return
 }
+
+// -----
+
+// CHECK-LABEL: llvm.func @decl(i64)
+// CHECK-LABEL: llvm.func @func(%arg0: i64) {
+// CHECK-NEXT:  llvm.call @decl(%arg0) : (i64) -> ()
+// CHECK-NEXT:  llvm.return
+
+llvm.func @decl(i64)
+
+llvm.func @func(%lb : i64) -> () {
+  llvm.call @decl(%lb) : (i64) -> ()
+  llvm.return
+}