[flang-commits] [flang] 72e5991 - [Flang]Fix another way to crash SimplifyIntrinsics
Mats Petersson via flang-commits
flang-commits at lists.llvm.org
Fri Aug 19 11:01:02 PDT 2022
Author: Mats Petersson
Date: 2022-08-19T19:00:30+01:00
New Revision: 72e599197c77d95ca2e3c4a7ffe82b739981da75
URL: https://github.com/llvm/llvm-project/commit/72e599197c77d95ca2e3c4a7ffe82b739981da75
DIFF: https://github.com/llvm/llvm-project/commit/72e599197c77d95ca2e3c4a7ffe82b739981da75.diff
LOG: [Flang]Fix another way to crash SimplifyIntrinsics
Under some conditions, the defining op may be NULL, so
accept that rahter than try to use it and crash!
Adds test to prevent regression
Fixes github issue #57201
Reviewed By: vzakhari
Differential Revision: https://reviews.llvm.org/D132238
Added:
Modified:
flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
flang/test/Transforms/simplifyintrinsics.fir
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
index ed1d1be4b90c4..75ecb2af8865e 100644
--- a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
+++ b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp
@@ -331,8 +331,8 @@ static bool isZero(mlir::Value val) {
static mlir::Value findShape(mlir::Value val) {
if (auto op = expectConvertOp(val)) {
assert(op->getOperands().size() != 0);
- if (auto box =
- mlir::dyn_cast<fir::EmboxOp>(op->getOperand(0).getDefiningOp()))
+ if (auto box = mlir::dyn_cast_or_null<fir::EmboxOp>(
+ op->getOperand(0).getDefiningOp()))
return box.getShape();
}
return {};
diff --git a/flang/test/Transforms/simplifyintrinsics.fir b/flang/test/Transforms/simplifyintrinsics.fir
index f51d82f6959a0..2d6e39bf1fffc 100644
--- a/flang/test/Transforms/simplifyintrinsics.fir
+++ b/flang/test/Transforms/simplifyintrinsics.fir
@@ -347,6 +347,37 @@ module attributes {fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.targ
// CHECK-LABEL @sum_dim() {
// CHECK: return
+
+// -----
+
+// Using an unknown size.
+module attributes {fir.defaultkind = "a1c4d8i4l4r4", fir.kindmap = "", llvm.target_triple = "native"} {
+ func.func @sum_1d_unknown(%arg0: !fir.box<!fir.array<?xi32>> {fir.bindc_name = "a"}) -> i32 {
+ %0 = fir.alloca i32 {bindc_name = "test_sum_1", uniq_name = "_QFtest_sum_1Etest_sum_1"}
+ %1 = fir.absent !fir.box<i1>
+ %c0 = arith.constant 0 : index
+ %2 = fir.address_of(@_QQcl.2E2F696D61785F312E66393000) : !fir.ref<!fir.char<1,13>>
+ %c5_i32 = arith.constant 5 : i32
+ %3 = fir.convert %arg0 : (!fir.box<!fir.array<?xi32>>) -> !fir.box<none>
+ %4 = fir.convert %2 : (!fir.ref<!fir.char<1,13>>) -> !fir.ref<i8>
+ %5 = fir.convert %c0 : (index) -> i32
+ %6 = fir.convert %1 : (!fir.box<i1>) -> !fir.box<none>
+ %7 = fir.call @_FortranASumlInteger4(%3, %4, %c5_i32, %5, %6) : (!fir.box<none>, !fir.ref<i8>, i32, i32, !fir.box<none>) -> i32
+ fir.store %7 to %0 : !fir.ref<i32>
+ %8 = fir.load %0 : !fir.ref<i32>
+ return %8 : i32
+ }
+ func.func private @_FortranASumInteger4(!fir.box<none>, !fir.ref<i8>, i32, i32, !fir.box<none>) -> i32 attributes {fir.runtime}
+ fir.global linkonce @_QQcl.2E2F696D61785F312E66393000 constant : !fir.char<1,13> {
+ %0 = fir.string_lit "./imax_1.f90\00"(13) : !fir.char<1,13>
+ fir.has_value %0 : !fir.char<1,13>
+ }
+}
+
+// Just check that SOMETHING is being output.
+// CHECK-LABEL @sum_1d_unknown() {
+// CHECK: return
+
// -----
func.func @dot_f32(%arg0: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "a"}, %arg1: !fir.box<!fir.array<?xf32>> {fir.bindc_name = "b"}) -> f32 {
More information about the flang-commits
mailing list