Index: flang/test/Lower/Intrinsics/get_command_argument-optional.f90 =================================================================== --- flang/test/Lower/Intrinsics/get_command_argument-optional.f90 +++ flang/test/Lower/Intrinsics/get_command_argument-optional.f90 @@ -2,42 +2,42 @@ ! RUN: bbc -emit-fir %s -o - | FileCheck %s ! CHECK-LABEL: func @_QPtest( -! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref {fir.bindc_name = "number", fir.optional}, -! CHECK-SAME: %[[VAL_1:.*]]: !fir.boxchar<1> {fir.bindc_name = "value", fir.optional}, -! CHECK-SAME: %[[VAL_2:.*]]: !fir.ref {fir.bindc_name = "length", fir.optional}, -! CHECK-SAME: %[[VAL_3:.*]]: !fir.ref {fir.bindc_name = "status", fir.optional}, -! CHECK-SAME: %[[VAL_4:.*]]: !fir.boxchar<1> {fir.bindc_name = "errmsg", fir.optional}) { +! CHECK-SAME: %[[numberParam:.*]]: !fir.ref {fir.bindc_name = "number", fir.optional}, +! CHECK-SAME: %[[valueParam:.*]]: !fir.boxchar<1> {fir.bindc_name = "value", fir.optional}, +! CHECK-SAME: %[[lengthParam:.*]]: !fir.ref {fir.bindc_name = "length", fir.optional}, +! CHECK-SAME: %[[statusParam:.*]]: !fir.ref {fir.bindc_name = "status", fir.optional}, +! CHECK-SAME: %[[errmsgParam:.*]]: !fir.boxchar<1> {fir.bindc_name = "errmsg", fir.optional}) { subroutine test(number, value, length, status, errmsg) integer, optional :: number, status, length character(*), optional :: value, errmsg ! Note: number cannot be absent call get_command_argument(number, value, length, status, errmsg) -! CHECK: %[[VAL_5:.*]]:2 = fir.unboxchar %[[VAL_4]] : (!fir.boxchar<1>) -> (!fir.ref>, index) -! CHECK: %[[VAL_6:.*]]:2 = fir.unboxchar %[[VAL_1]] : (!fir.boxchar<1>) -> (!fir.ref>, index) -! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_0]] : !fir.ref -! CHECK: %[[VAL_8:.*]] = fir.is_present %[[VAL_6]]#0 : (!fir.ref>) -> i1 -! CHECK: %[[VAL_9:.*]] = fir.embox %[[VAL_6]]#0 typeparams %[[VAL_6]]#1 : (!fir.ref>, index) -> !fir.box> -! CHECK: %[[VAL_10:.*]] = fir.absent !fir.box> -! CHECK: %[[VAL_11:.*]] = arith.select %[[VAL_8]], %[[VAL_9]], %[[VAL_10]] : !fir.box> -! CHECK: %[[VAL_12:.*]] = fir.is_present %[[VAL_5]]#0 : (!fir.ref>) -> i1 -! CHECK: %[[VAL_13:.*]] = fir.embox %[[VAL_5]]#0 typeparams %[[VAL_5]]#1 : (!fir.ref>, index) -> !fir.box> -! CHECK: %[[VAL_14:.*]] = fir.absent !fir.box> -! CHECK: %[[VAL_15:.*]] = arith.select %[[VAL_12]], %[[VAL_13]], %[[VAL_14]] : !fir.box> -! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_11]] : (!fir.box>) -> !fir.box -! CHECK: %[[VAL_17:.*]] = fir.convert %[[VAL_15]] : (!fir.box>) -> !fir.box -! CHECK: %[[VAL_18:.*]] = fir.call @_FortranAArgumentValue(%[[VAL_7]], %[[VAL_16]], %[[VAL_17]]) : (i32, !fir.box, !fir.box) -> i32 -! CHECK: %[[VAL_19:.*]] = fir.convert %[[VAL_3]] : (!fir.ref) -> i64 -! CHECK: %[[VAL_20:.*]] = arith.constant 0 : i64 -! CHECK: %[[VAL_21:.*]] = arith.cmpi ne, %[[VAL_19]], %[[VAL_20]] : i64 -! CHECK: fir.if %[[VAL_21]] { -! CHECK: fir.store %[[VAL_18]] to %[[VAL_3]] : !fir.ref +! CHECK: %[[errmsgUnboxed:.*]]:2 = fir.unboxchar %[[errmsgParam]] : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[valueUnboxed:.*]]:2 = fir.unboxchar %[[valueParam]] : (!fir.boxchar<1>) -> (!fir.ref>, index) +! CHECK: %[[number:.*]] = fir.load %[[numberParam]] : !fir.ref +! CHECK: %[[valueIsPresent:.*]] = fir.is_present %[[valueUnboxed]]#0 : (!fir.ref>) -> i1 +! CHECK: %[[valueReboxed:.*]] = fir.embox %[[valueUnboxed]]#0 typeparams %[[valueUnboxed]]#1 : (!fir.ref>, index) -> !fir.box> +! CHECK: %[[valueAbsent:.*]] = fir.absent !fir.box> +! CHECK: %[[valueOrAbsent:.*]] = arith.select %[[valueIsPresent]], %[[valueReboxed]], %[[valueAbsent]] : !fir.box> +! CHECK: %[[errmsgIsPresent:.*]] = fir.is_present %[[errmsgUnboxed]]#0 : (!fir.ref>) -> i1 +! CHECK: %[[errmsgReboxed:.*]] = fir.embox %[[errmsgUnboxed]]#0 typeparams %[[errmsgUnboxed]]#1 : (!fir.ref>, index) -> !fir.box> +! CHECK: %[[errmsgAbsent:.*]] = fir.absent !fir.box> +! CHECK: %[[errmsgOrAbsent:.*]] = arith.select %[[errmsgIsPresent]], %[[errmsgReboxed]], %[[errmsgAbsent]] : !fir.box> +! CHECK: %[[value:.*]] = fir.convert %[[valueOrAbsent]] : (!fir.box>) -> !fir.box +! CHECK: %[[errmsg:.*]] = fir.convert %[[errmsgOrAbsent]] : (!fir.box>) -> !fir.box +! CHECK: %[[status:.*]] = fir.call @_FortranAArgumentValue(%[[number]], %[[value]], %[[errmsg]]) : (i32, !fir.box, !fir.box) -> i32 +! CHECK: %[[statusI64:.*]] = fir.convert %[[statusParam]] : (!fir.ref) -> i64 +! CHECK: %[[zero:.*]] = arith.constant 0 : i64 +! CHECK: %[[statusIsNonNull:.*]] = arith.cmpi ne, %[[statusI64]], %[[zero]] : i64 +! CHECK: fir.if %[[statusIsNonNull]] { +! CHECK: fir.store %[[status]] to %[[statusParam]] : !fir.ref ! CHECK: } -! CHECK: %[[VAL_22:.*]] = fir.convert %[[VAL_2]] : (!fir.ref) -> i64 -! CHECK: %[[VAL_23:.*]] = arith.constant 0 : i64 -! CHECK: %[[VAL_24:.*]] = arith.cmpi ne, %[[VAL_22]], %[[VAL_23]] : i64 -! CHECK: fir.if %[[VAL_24]] { -! CHECK: %[[VAL_25:.*]] = fir.call @_FortranAArgumentLength(%[[VAL_7]]) : (i32) -> i64 -! CHECK: %[[VAL_26:.*]] = fir.convert %[[VAL_25]] : (i64) -> i32 -! CHECK: fir.store %[[VAL_26]] to %[[VAL_2]] : !fir.ref +! CHECK: %[[lengthI64:.*]] = fir.convert %[[lengthParam]] : (!fir.ref) -> i64 +! CHECK: %[[zero2:.*]] = arith.constant 0 : i64 +! CHECK: %[[lengthIsNonNull:.*]] = arith.cmpi ne, %[[lengthI64]], %[[zero2]] : i64 +! CHECK: fir.if %[[lengthIsNonNull]] { +! CHECK: %[[length:.*]] = fir.call @_FortranAArgumentLength(%[[number]]) : (i32) -> i64 +! CHECK: %[[lengthTrunc:.*]] = fir.convert %[[length]] : (i64) -> i32 +! CHECK: fir.store %[[lengthTrunc]] to %[[lengthParam]] : !fir.ref ! CHECK: } end subroutine