Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Lower / Intrinsics / get_command.f90
blob13cac00d822ac5b86530c27d585da4df450e73f4
1 ! RUN: bbc -emit-fir %s -o - | FileCheck %s
3 ! CHECK-LABEL: func.func @_QPcommand_only() {
4 ! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.char<1,10> {bindc_name = "cmd", uniq_name = "_QFcommand_onlyEcmd"}
5 ! CHECK: %[[VAL_1:.*]] = fir.embox %[[VAL_0]] : (!fir.ref<!fir.char<1,10>>) -> !fir.box<!fir.char<1,10>>
6 ! CHECK: %[[VAL_2:.*]] = fir.absent !fir.box<none>
7 ! CHECK: %[[VAL_3:.*]] = fir.absent !fir.box<none>
8 ! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_1]] : (!fir.box<!fir.char<1,10>>) -> !fir.box<none>
9 ! CHECK: %[[VAL_8:.*]] = fir.call @_FortranAGetCommand(%[[VAL_6]], %[[VAL_2]], %[[VAL_3]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.box<none>, !fir.box<none>, !fir.box<none>, !fir.ref<i8>, i32) -> i32
10 ! CHECK: return
11 ! CHECK: }
13 subroutine command_only()
14 character(10) :: cmd
15 call get_command(cmd)
16 end
18 ! CHECK-LABEL: func.func @_QPlength_only() {
19 ! CHECK: %[[VAL_0:.*]] = fir.alloca i32 {bindc_name = "len", uniq_name = "_QFlength_onlyElen"}
20 ! CHECK: %[[VAL_1:.*]] = fir.embox %[[VAL_0]] : (!fir.ref<i32>) -> !fir.box<i32>
21 ! CHECK: %[[VAL_2:.*]] = fir.absent !fir.box<none>
22 ! CHECK: %[[VAL_3:.*]] = fir.absent !fir.box<none>
23 ! CHECK: %[[VAL_6:.*]] = fir.convert %[[VAL_1]] : (!fir.box<i32>) -> !fir.box<none>
24 ! CHECK: %[[VAL_8:.*]] = fir.call @_FortranAGetCommand(%[[VAL_2]], %[[VAL_6]], %[[VAL_3]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.box<none>, !fir.box<none>, !fir.box<none>, !fir.ref<i8>, i32) -> i32
25 ! CHECK: return
26 ! CHECK: }
28 subroutine length_only()
29 integer :: len
30 call get_command(length=len)
31 end
33 ! CHECK-LABEL: func.func @_QPstatus_only() {
34 ! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.char<1,10> {bindc_name = "cmd", uniq_name = "_QFstatus_onlyEcmd"}
35 ! CHECK: %[[VAL_1:.*]] = fir.alloca i32 {bindc_name = "stat", uniq_name = "_QFstatus_onlyEstat"}
36 ! CHECK: %[[VAL_2:.*]] = fir.embox %[[VAL_0]] : (!fir.ref<!fir.char<1,10>>) -> !fir.box<!fir.char<1,10>>
37 ! CHECK: %[[VAL_3:.*]] = fir.absent !fir.box<none>
38 ! CHECK: %[[VAL_4:.*]] = fir.absent !fir.box<none>
39 ! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_2]] : (!fir.box<!fir.char<1,10>>) -> !fir.box<none>
40 ! CHECK: %[[VAL_9:.*]] = fir.call @_FortranAGetCommand(%[[VAL_7]], %[[VAL_3]], %[[VAL_4]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.box<none>, !fir.box<none>, !fir.box<none>, !fir.ref<i8>, i32) -> i32
41 ! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_1]] : (!fir.ref<i32>) -> i64
42 ! CHECK: %[[VAL_11:.*]] = arith.constant 0 : i64
43 ! CHECK: %[[VAL_12:.*]] = arith.cmpi ne, %[[VAL_10]], %[[VAL_11]] : i64
44 ! CHECK: fir.if %[[VAL_12]] {
45 ! CHECK: fir.store %[[VAL_9]] to %[[VAL_1]] : !fir.ref<i32>
46 ! CHECK: }
47 ! CHECK: return
48 ! CHECK: }
50 subroutine status_only()
51 character(10) :: cmd
52 integer :: stat
53 call get_command(cmd, status=stat)
54 end
56 ! CHECK-LABEL: func.func @_QPerrmsg_only() {
57 ! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.char<1,10> {bindc_name = "cmd", uniq_name = "_QFerrmsg_onlyEcmd"}
58 ! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.char<1,50> {bindc_name = "err", uniq_name = "_QFerrmsg_onlyEerr"}
59 ! CHECK: %[[VAL_2:.*]] = fir.embox %[[VAL_0]] : (!fir.ref<!fir.char<1,10>>) -> !fir.box<!fir.char<1,10>>
60 ! CHECK: %[[VAL_3:.*]] = fir.embox %[[VAL_1]] : (!fir.ref<!fir.char<1,50>>) -> !fir.box<!fir.char<1,50>>
61 ! CHECK: %[[VAL_4:.*]] = fir.absent !fir.box<none>
62 ! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_2]] : (!fir.box<!fir.char<1,10>>) -> !fir.box<none>
63 ! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_3]] : (!fir.box<!fir.char<1,50>>) -> !fir.box<none>
64 ! CHECK: %[[VAL_10:.*]] = fir.call @_FortranAGetCommand(%[[VAL_7]], %[[VAL_4]], %[[VAL_8]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.box<none>, !fir.box<none>, !fir.box<none>, !fir.ref<i8>, i32) -> i32
65 ! CHECK: return
66 ! CHECK: }
68 subroutine errmsg_only()
69 character(10) :: cmd
70 character(50) :: err
71 call get_command(cmd, errmsg=err)
72 end
74 ! CHECK-LABEL: func.func @_QPcommand_status() {
75 ! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.char<1,10> {bindc_name = "cmd", uniq_name = "_QFcommand_statusEcmd"}
76 ! CHECK: %[[VAL_1:.*]] = fir.alloca i32 {bindc_name = "stat", uniq_name = "_QFcommand_statusEstat"}
77 ! CHECK: %[[VAL_2:.*]] = fir.embox %[[VAL_0]] : (!fir.ref<!fir.char<1,10>>) -> !fir.box<!fir.char<1,10>>
78 ! CHECK: %[[VAL_3:.*]] = fir.absent !fir.box<none>
79 ! CHECK: %[[VAL_4:.*]] = fir.absent !fir.box<none>
80 ! CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_2]] : (!fir.box<!fir.char<1,10>>) -> !fir.box<none>
81 ! CHECK: %[[VAL_9:.*]] = fir.call @_FortranAGetCommand(%[[VAL_7]], %[[VAL_3]], %[[VAL_4]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.box<none>, !fir.box<none>, !fir.box<none>, !fir.ref<i8>, i32) -> i32
82 ! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_1]] : (!fir.ref<i32>) -> i64
83 ! CHECK: %[[VAL_11:.*]] = arith.constant 0 : i64
84 ! CHECK: %[[VAL_12:.*]] = arith.cmpi ne, %[[VAL_10]], %[[VAL_11]] : i64
85 ! CHECK: fir.if %[[VAL_12]] {
86 ! CHECK: fir.store %[[VAL_9]] to %[[VAL_1]] : !fir.ref<i32>
87 ! CHECK: }
88 ! CHECK: return
89 ! CHECK: }
91 subroutine command_status()
92 character(10) :: cmd
93 integer :: stat
94 call get_command(cmd, status=stat)
95 end
97 ! CHECK-LABEL: func.func @_QPall_args() {
98 ! CHECK: %[[VAL_0:.*]] = fir.alloca !fir.char<1,10> {bindc_name = "cmd", uniq_name = "_QFall_argsEcmd"}
99 ! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.char<1,50> {bindc_name = "err", uniq_name = "_QFall_argsEerr"}
100 ! CHECK: %[[VAL_2:.*]] = fir.alloca i32 {bindc_name = "len", uniq_name = "_QFall_argsElen"}
101 ! CHECK: %[[VAL_3:.*]] = fir.alloca i32 {bindc_name = "stat", uniq_name = "_QFall_argsEstat"}
102 ! CHECK: %[[VAL_4:.*]] = fir.embox %[[VAL_0]] : (!fir.ref<!fir.char<1,10>>) -> !fir.box<!fir.char<1,10>>
103 ! CHECK: %[[VAL_5:.*]] = fir.embox %[[VAL_2]] : (!fir.ref<i32>) -> !fir.box<i32>
104 ! CHECK: %[[VAL_6:.*]] = fir.embox %[[VAL_1]] : (!fir.ref<!fir.char<1,50>>) -> !fir.box<!fir.char<1,50>>
105 ! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_4]] : (!fir.box<!fir.char<1,10>>) -> !fir.box<none>
106 ! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_5]] : (!fir.box<i32>) -> !fir.box<none>
107 ! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_6]] : (!fir.box<!fir.char<1,50>>) -> !fir.box<none>
108 ! CHECK: %[[VAL_13:.*]] = fir.call @_FortranAGetCommand(%[[VAL_9]], %[[VAL_10]], %[[VAL_11]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.box<none>, !fir.box<none>, !fir.box<none>, !fir.ref<i8>, i32) -> i32
109 ! CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<i32>) -> i64
110 ! CHECK: %[[VAL_15:.*]] = arith.constant 0 : i64
111 ! CHECK: %[[VAL_16:.*]] = arith.cmpi ne, %[[VAL_14]], %[[VAL_15]] : i64
112 ! CHECK: fir.if %[[VAL_16]] {
113 ! CHECK: fir.store %[[VAL_13]] to %[[VAL_3]] : !fir.ref<i32>
114 ! CHECK: }
115 ! CHECK: return
116 ! CHECK: }
118 subroutine all_args()
119 character(10) :: cmd
120 character(50) :: err
121 integer :: len, stat
122 call get_command(cmd, len, stat, err)