diff --git a/flang/lib/Lower/IntrinsicCall.cpp b/flang/lib/Lower/IntrinsicCall.cpp --- a/flang/lib/Lower/IntrinsicCall.cpp +++ b/flang/lib/Lower/IntrinsicCall.cpp @@ -719,7 +719,7 @@ /*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 --- /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 {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) -> i1 +! CHECK: %[[VAL_2:.*]] = fir.if %[[VAL_1]] -> (i32) { +! CHECK: %[[VAL_3:.*]] = fir.load %[[VAL_0]] : !fir.ref +! 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.bindc_name = "status"}) { +subroutine exit_pointer(status) + integer, pointer :: status + call exit(status) +! CHECK: %[[VAL_1:.*]] = fir.load %[[VAL_0]] : !fir.ref>> +! CHECK: %[[VAL_2:.*]] = fir.box_addr %[[VAL_1]] : (!fir.box>) -> !fir.ptr +! CHECK: %[[VAL_3:.*]] = fir.convert %[[VAL_2]] : (!fir.ptr) -> 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>> +! CHECK: %[[VAL_8:.*]] = fir.box_addr %[[VAL_7]] : (!fir.box>) -> !fir.ptr +! CHECK: %[[VAL_9:.*]] = fir.load %[[VAL_8]] : !fir.ptr +! 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