[flang-commits] [flang] 4535bb9 - [flang] Handle dynamically optional argument in EXIT
Jean Perier via flang-commits
flang-commits at lists.llvm.org
Fri Apr 8 06:52:15 PDT 2022
Author: Jean Perier
Date: 2022-04-08T15:51:44+02:00
New Revision: 4535bb9b80ce61aab89603b7fde6fe56e8f87121
URL: https://github.com/llvm/llvm-project/commit/4535bb9b80ce61aab89603b7fde6fe56e8f87121
DIFF: https://github.com/llvm/llvm-project/commit/4535bb9b80ce61aab89603b7fde6fe56e8f87121.diff
LOG: [flang] Handle dynamically optional argument in EXIT
The actual argument passed to STATUS may be a dummy OPTIONAL or a
disassociated POINTER/unallocated ALLOCATABLE.
Differential Revision: https://reviews.llvm.org/D123380
Added:
flang/test/Lower/Intrinsics/exit-2.f90
Modified:
flang/lib/Lower/IntrinsicCall.cpp
Removed:
################################################################################
diff --git a/flang/lib/Lower/IntrinsicCall.cpp b/flang/lib/Lower/IntrinsicCall.cpp
index a37f659ffb2ac..9baedab34c462 100644
--- a/flang/lib/Lower/IntrinsicCall.cpp
+++ b/flang/lib/Lower/IntrinsicCall.cpp
@@ -729,7 +729,7 @@ static constexpr IntrinsicHandler handlers[]{
/*isElemental=*/false},
{"exit",
&I::genExit,
- {{{"status", asValue}}},
+ {{{"status", asValue, handleDynamicOptional}}},
/*isElemental=*/false},
{"exponent", &I::genExponent},
{"floor", &I::genFloor},
diff --git a/flang/test/Lower/Intrinsics/exit-2.f90 b/flang/test/Lower/Intrinsics/exit-2.f90
new file mode 100644
index 0000000000000..5f2b31f2a5320
--- /dev/null
+++ b/flang/test/Lower/Intrinsics/exit-2.f90
@@ -0,0 +1,40 @@
+! Test EXIT with dynamically optional arguments.
+! RUN: bbc -emit-fir %s -o - | FileCheck %s
+
+! CHECK-LABEL: func @_QPexit_opt_dummy(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<i32> {fir.bindc_name = "status", fir.optional}) {
+subroutine exit_opt_dummy(status)
+ integer, optional :: status
+ call exit(status)
+! CHECK: %[[VAL_1:.*]] = fir.is_present %[[VAL_0]] : (!fir.ref<i32>) -> i1
+! CHECK: %[[VAL_2:.*]] = fir.if %[[VAL_1]] -> (i32) {
+! CHECK: %[[VAL_3:.*]] = fir.load %[[VAL_0]] : !fir.ref<i32>
+! CHECK: fir.result %[[VAL_3]] : i32
+! CHECK: } else {
+! CHECK: %[[VAL_4:.*]] = arith.constant 0 : i32
+! CHECK: fir.result %[[VAL_4]] : i32
+! CHECK: }
+! CHECK: %[[VAL_5:.*]] = fir.call @_FortranAExit(%[[VAL_6:.*]]) : (i32) -> none
+end subroutine
+
+! CHECK-LABEL: func @_QPexit_pointer(
+! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<i32>>> {fir.bindc_name = "status"}) {
+subroutine exit_pointer(status)
+ integer, pointer :: status
+ call exit(status)
+! CHECK: %[[VAL_1:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.ptr<i32>>>
+! CHECK: %[[VAL_2:.*]] = fir.box_addr %[[VAL_1]] : (!fir.box<!fir.ptr<i32>>) -> !fir.ptr<i32>
+! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.ptr<i32>) -> i64
+! CHECK: %[[VAL_4:.*]] = arith.constant 0 : i64
+! CHECK: %[[VAL_5:.*]] = arith.cmpi ne, %[[VAL_3]], %[[VAL_4]] : i64
+! CHECK: %[[VAL_6:.*]] = fir.if %[[VAL_5]] -> (i32) {
+! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_0]] : !fir.ref<!fir.box<!fir.ptr<i32>>>
+! CHECK: %[[VAL_8:.*]] = fir.box_addr %[[VAL_7]] : (!fir.box<!fir.ptr<i32>>) -> !fir.ptr<i32>
+! CHECK: %[[VAL_9:.*]] = fir.load %[[VAL_8]] : !fir.ptr<i32>
+! CHECK: fir.result %[[VAL_9]] : i32
+! CHECK: } else {
+! CHECK: %[[VAL_10:.*]] = arith.constant 0 : i32
+! CHECK: fir.result %[[VAL_10]] : i32
+! CHECK: }
+! CHECK: %[[VAL_11:.*]] = fir.call @_FortranAExit(%[[VAL_12:.*]]) : (i32) -> none
+end subroutine
More information about the flang-commits
mailing list