From: Mats Petersson Date: Fri, 19 Aug 2022 12:34:48 +0000 (+0100) Subject: [Flang]Fix another way to crash SimplifyIntrinsics X-Git-Tag: upstream/17.0.6~35970 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=72e599197c77d95ca2e3c4a7ffe82b739981da75;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp index ed1d1be..75ecb2a 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(op->getOperand(0).getDefiningOp())) + if (auto box = mlir::dyn_cast_or_null( + op->getOperand(0).getDefiningOp())) return box.getShape(); } return {}; diff --git a/flang/test/Transforms/simplifyintrinsics.fir b/flang/test/Transforms/simplifyintrinsics.fir index f51d82f..2d6e39b 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.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 + %c0 = arith.constant 0 : index + %2 = fir.address_of(@_QQcl.2E2F696D61785F312E66393000) : !fir.ref> + %c5_i32 = arith.constant 5 : i32 + %3 = fir.convert %arg0 : (!fir.box>) -> !fir.box + %4 = fir.convert %2 : (!fir.ref>) -> !fir.ref + %5 = fir.convert %c0 : (index) -> i32 + %6 = fir.convert %1 : (!fir.box) -> !fir.box + %7 = fir.call @_FortranASumlInteger4(%3, %4, %c5_i32, %5, %6) : (!fir.box, !fir.ref, i32, i32, !fir.box) -> i32 + fir.store %7 to %0 : !fir.ref + %8 = fir.load %0 : !fir.ref + return %8 : i32 + } + func.func private @_FortranASumInteger4(!fir.box, !fir.ref, i32, i32, !fir.box) -> 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.bindc_name = "a"}, %arg1: !fir.box> {fir.bindc_name = "b"}) -> f32 {