! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck --check-prefixes=CHECK,CHECK-32 -DDEFAULT_INTEGER_SIZE=32 %s ! RUN: %flang_fc1 -fdefault-integer-8 -emit-hlfir %s -o - | FileCheck --check-prefixes=CHECK,CHECK-64 -DDEFAULT_INTEGER_SIZE=64 %s ! CHECK-LABEL: func @_QPnumber_only( ! CHECK-SAME: %[[num:.*]]: !fir.ref{{.*}}) { subroutine number_only(num) integer :: num call get_command_argument(num) ! CHECK-NOT: fir.call @_FortranAGetCommandArgument ! CHECK: return end subroutine number_only ! CHECK-LABEL: func @_QPnumber_and_value_only( ! CHECK-SAME: %[[num:.*]]: !fir.ref{{.*}}, %[[value:.*]]: !fir.boxchar<1>{{.*}}) { subroutine number_and_value_only(num, value) integer :: num character(len=32) :: value call get_command_argument(num, value) ! CHECK: %[[valueUnboxed:.*]]:2 = fir.unboxchar %[[value]] : (!fir.boxchar<1>) -> (!fir.ref>, index) ! CHECK: %[[valueCast:.*]] = fir.convert %[[valueUnboxed]]#0 : (!fir.ref>) -> !fir.ref> ! CHECK: hlfir.declare %[[valueCast]] ! CHECK: %[[numLoad:.*]] = fir.load {{.*}} : !fir.ref ! CHECK: %[[valueBoxed:.*]] = fir.embox {{.*}} : (!fir.ref>) -> !fir.box> ! CHECK: %[[length:.*]] = fir.absent !fir.box ! CHECK: %[[errmsg:.*]] = fir.absent !fir.box ! CHECK: %[[sourceFileString:.*]] = fir.address_of(@_QQcl{{.*}}) : !fir.ref> ! CHECK: %[[sourceLine:.*]] = arith.constant [[# @LINE - 9]] : i32 ! CHECK-64: %[[numCast:.*]] = fir.convert %[[numLoad]] : (i[[DEFAULT_INTEGER_SIZE]]) -> i32 ! CHECK: %[[valueBoxedCast:.*]] = fir.convert %[[valueBoxed]] : (!fir.box>) -> !fir.box ! CHECK: %[[sourceFile:.*]] = fir.convert %[[sourceFileString]] : (!fir.ref>) -> !fir.ref ! CHECK-32: fir.call @_FortranAGetCommandArgument(%[[numLoad]], %[[valueBoxedCast]], %[[length]], %[[errmsg]], %[[sourceFile]], %[[sourceLine]]) {{.*}}: (i32, !fir.box, !fir.box, !fir.box, !fir.ref, i32) -> i32 ! CHECK-64: fir.call @_FortranAGetCommandArgument(%[[numCast]], %[[valueBoxedCast]], %[[length]], %[[errmsg]], %[[sourceFile]], %[[sourceLine]]) {{.*}}: (i32, !fir.box, !fir.box, !fir.box, !fir.ref, i32) -> i32 end subroutine number_and_value_only ! CHECK-LABEL: func @_QPall_arguments( ! CHECK-SAME: %[[num:[^:]*]]: !fir.ref{{.*}}, %[[value:.*]]: !fir.boxchar<1>{{.*}}, %[[length:[^:]*]]: !fir.ref{{.*}}, %[[status:.*]]: !fir.ref{{.*}}, %[[errmsg:.*]]: !fir.boxchar<1>{{.*}}) { subroutine all_arguments(num, value, length, status, errmsg) integer :: num, length, status character(len=32) :: value, errmsg call get_command_argument(num, value, length, status, errmsg) ! CHECK: %[[numLoad:.*]] = fir.load {{.*}} : !fir.ref ! CHECK: %[[valueBoxed:.*]] = fir.embox {{.*}} : (!fir.ref>) -> !fir.box> ! CHECK: %[[lengthBoxed:.*]] = fir.embox {{.*}} : (!fir.ref) -> !fir.box ! CHECK: %[[errmsgBoxed:.*]] = fir.embox {{.*}} : (!fir.ref>) -> !fir.box> ! CHECK: %[[sourceFileString:.*]] = fir.address_of(@_QQcl{{.*}}) : !fir.ref> ! CHECK: %[[sourceLine:.*]] = arith.constant [[# @LINE - 6]] : i32 ! CHECK-64: %[[numCast:.*]] = fir.convert %[[numLoad]] : (i64) -> i32 ! CHECK: %[[valueBuffer:.*]] = fir.convert %[[valueBoxed]] : (!fir.box>) -> !fir.box ! CHECK: %[[lengthBuffer:.*]] = fir.convert %[[lengthBoxed]] : (!fir.box) -> !fir.box ! CHECK: %[[errmsgBuffer:.*]] = fir.convert %[[errmsgBoxed]] : (!fir.box>) -> !fir.box ! CHECK: %[[sourceFile:.*]] = fir.convert %[[sourceFileString]] : (!fir.ref>) -> !fir.ref ! CHECK-32: %[[statusResult:.*]] = fir.call @_FortranAGetCommandArgument(%[[numLoad]], %[[valueBuffer]], %[[lengthBuffer]], %[[errmsgBuffer]], %[[sourceFile]], %[[sourceLine]]) {{.*}}: (i32, !fir.box, !fir.box, !fir.box, !fir.ref, i32) -> i32 ! CHECK-64: %[[statusResult32:.*]] = fir.call @_FortranAGetCommandArgument(%[[numCast]], %[[valueBuffer]], %[[lengthBuffer]], %[[errmsgBuffer]], %[[sourceFile]], %[[sourceLine]]) {{.*}}: (i32, !fir.box, !fir.box, !fir.box, !fir.ref, i32) -> i32 ! CHECK-64: %[[statusResult:.*]] = fir.convert %[[statusResult32]] : (i32) -> i64 ! CHECK: fir.store %[[statusResult]] to {{.*}} : !fir.ref end subroutine all_arguments ! CHECK-LABEL: func @_QPnumber_and_length_only( ! CHECK-SAME: %[[num:.*]]: !fir.ref{{.*}}, %[[length:.*]]: !fir.ref{{.*}}) { subroutine number_and_length_only(num, length) integer :: num, length call get_command_argument(num, LENGTH=length) ! CHECK: %[[numLoaded:.*]] = fir.load {{.*}} : !fir.ref ! CHECK: %[[lengthBoxed:.*]] = fir.embox {{.*}} : (!fir.ref) -> !fir.box ! CHECK: %[[value:.*]] = fir.absent !fir.box ! CHECK: %[[errmsg:.*]] = fir.absent !fir.box ! CHECK: %[[sourceFileString:.*]] = fir.address_of(@_QQcl{{.*}}) : !fir.ref> ! CHECK: %[[sourceLine:.*]] = arith.constant [[# @LINE - 6]] : i32 ! CHECK-64: %[[numCast:.*]] = fir.convert %[[numLoaded]] : (i64) -> i32 ! CHECK: %[[lengthBuffer:.*]] = fir.convert %[[lengthBoxed]] : (!fir.box) -> !fir.box ! CHECK: %[[sourceFile:.*]] = fir.convert %[[sourceFileString]] : (!fir.ref>) -> !fir.ref ! CHECK-32: fir.call @_FortranAGetCommandArgument(%[[numLoaded]], %[[value]], %[[lengthBuffer]], %[[errmsg]], %[[sourceFile]], %[[sourceLine]]) {{.*}}: (i32, !fir.box, !fir.box, !fir.box, !fir.ref, i32) -> i32 ! CHECK-64: fir.call @_FortranAGetCommandArgument(%[[numCast]], %[[value]], %[[lengthBuffer]], %[[errmsg]], %[[sourceFile]], %[[sourceLine]]) {{.*}}: (i32, !fir.box, !fir.box, !fir.box, !fir.ref, i32) -> i32 end subroutine number_and_length_only ! CHECK-LABEL: func @_QPnumber_and_status_only( ! CHECK-SAME: %[[num:.*]]: !fir.ref{{.*}}, %[[status:.*]]: !fir.ref{{.*}}) { subroutine number_and_status_only(num, status) integer :: num, status call get_command_argument(num, STATUS=status) ! CHECK: %[[numLoaded:.*]] = fir.load {{.*}} : !fir.ref ! CHECK: %[[value:.*]] = fir.absent !fir.box ! CHECK: %[[length:.*]] = fir.absent !fir.box ! CHECK: %[[errmsg:.*]] = fir.absent !fir.box ! CHECK: %[[sourceFileString:.*]] = fir.address_of(@_QQcl{{.*}}) : !fir.ref> ! CHECK: %[[sourceLine:.*]] = arith.constant [[# @LINE - 6]] : i32 ! CHECK-64: %[[numCast:.*]] = fir.convert %[[numLoaded]] : (i64) -> i32 ! CHECK: %[[sourceFile:.*]] = fir.convert %[[sourceFileString]] : (!fir.ref>) -> !fir.ref ! CHECK-32: %[[result:.*]] = fir.call @_FortranAGetCommandArgument(%[[numLoaded]], %[[value]], %[[length]], %[[errmsg]], %[[sourceFile]], %[[sourceLine]]) {{.*}}: (i32, !fir.box, !fir.box, !fir.box, !fir.ref, i32) -> i32 ! CHECK-64: %[[result32:.*]] = fir.call @_FortranAGetCommandArgument(%[[numCast]], %[[value]], %[[length]], %[[errmsg]], %[[sourceFile]], %[[sourceLine]]) {{.*}}: (i32, !fir.box, !fir.box, !fir.box, !fir.ref, i32) -> i32 ! CHECK-64: %[[result:.*]] = fir.convert %[[result32]] : (i32) -> i64 ! CHECK: fir.store %[[result]] to {{.*}} : !fir.ref end subroutine number_and_status_only ! CHECK-LABEL: func @_QPnumber_and_errmsg_only( ! CHECK-SAME: %[[num:.*]]: !fir.ref{{.*}}, %[[errmsg:.*]]: !fir.boxchar<1>{{.*}}) { subroutine number_and_errmsg_only(num, errmsg) integer :: num character(len=32) :: errmsg call get_command_argument(num, ERRMSG=errmsg) ! CHECK: %[[errmsgUnboxed:.*]]:2 = fir.unboxchar %[[errmsg]] : (!fir.boxchar<1>) -> (!fir.ref>, index) ! CHECK: %[[errmsgCast:.*]] = fir.convert %[[errmsgUnboxed]]#0 : (!fir.ref>) -> !fir.ref> ! CHECK: hlfir.declare %[[errmsgCast]] ! CHECK: %[[numUnboxed:.*]] = fir.load {{.*}} : !fir.ref ! CHECK: %[[errmsgBoxed:.*]] = fir.embox {{.*}} : (!fir.ref>) -> !fir.box> ! CHECK: %[[value:.*]] = fir.absent !fir.box ! CHECK: %[[length:.*]] = fir.absent !fir.box ! CHECK: %[[sourceFileString:.*]] = fir.address_of(@_QQcl{{.*}}) : !fir.ref> ! CHECK: %[[sourceLine:.*]] = arith.constant [[# @LINE - 9]] : i32 ! CHECK-64: %[[numCast:.*]] = fir.convert %[[numUnboxed]] : (i64) -> i32 ! CHECK: %[[errmsgBoxedCast:.*]] = fir.convert %[[errmsgBoxed]] : (!fir.box>) -> !fir.box ! CHECK: %[[sourceFile:.*]] = fir.convert %[[sourceFileString]] : (!fir.ref>) -> !fir.ref ! CHECK-32: fir.call @_FortranAGetCommandArgument(%[[numUnboxed]], %[[value]], %[[length]], %[[errmsgBoxedCast]], %[[sourceFile]], %[[sourceLine]]) {{.*}}: (i32, !fir.box, !fir.box, !fir.box, !fir.ref, i32) -> i32 ! CHECK-64: fir.call @_FortranAGetCommandArgument(%[[numCast]], %[[value]], %[[length]], %[[errmsgBoxedCast]], %[[sourceFile]], %[[sourceLine]]) {{.*}}: (i32, !fir.box, !fir.box, !fir.box, !fir.ref, i32) -> i32 end subroutine number_and_errmsg_only