1 // RUN: fir-opt --target-rewrite="target=i386-unknown-linux-gnu" %s | FileCheck %s --check-prefix=INT32
2 // RUN: fir-opt --target-rewrite="target=x86_64-unknown-linux-gnu" %s | FileCheck %s --check-prefix=INT64
3 // RUN: fir-opt --target-rewrite="target=aarch64-unknown-linux-gnu" %s | FileCheck %s --check-prefix=INT64
4 // RUN: fir-opt --target-rewrite="target=powerpc64le-unknown-linux-gnu" %s | FileCheck %s --check-prefix=INT64
5 // RUN: fir-opt --target-rewrite="target=amdgcn-amd-amdhsa" %s | FileCheck %s --check-prefix=INT64
6 // RUN: fir-opt --target-rewrite="target=loongarch64-unknown-linux-gnu" %s | FileCheck %s --check-prefix=INT64
8 // Test that we rewrite the signatures and bodies of functions that take boxchar
10 // INT32-LABEL: @boxcharparams
11 // INT32-SAME: ([[ARG0:%[0-9A-Za-z]+]]: !fir.ref<!fir.char<1,?>>, [[ARG1:%[0-9A-Za-z]+]]: !fir.ref<!fir.char<1,?>>, [[ARG2:%[0-9A-Za-z]+]]: i32, [[ARG3:%[0-9A-Za-z]+]]: i32) -> i64
12 // INT64-LABEL: @boxcharparams
13 // INT64-SAME: ([[ARG0:%[0-9A-Za-z]+]]: !fir.ref<!fir.char<1,?>>, [[ARG1:%[0-9A-Za-z]+]]: !fir.ref<!fir.char<1,?>>, [[ARG2:%[0-9A-Za-z]+]]: i64, [[ARG3:%[0-9A-Za-z]+]]: i64) -> i64
14 func.func @boxcharparams(%arg0 : !fir.boxchar<1>, %arg1 : !fir.boxchar<1>) -> i64 {
15 // INT32-DAG: [[B0:%[0-9]+]] = fir.emboxchar [[ARG1]], [[ARG3]] : (!fir.ref<!fir.char<1,?>>, i32) -> !fir.boxchar<1>
16 // INT32-DAG: [[B1:%[0-9]+]] = fir.emboxchar [[ARG0]], [[ARG2]] : (!fir.ref<!fir.char<1,?>>, i32) -> !fir.boxchar<1>
17 // INT32-DAG: fir.unboxchar [[B0]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1>>, i64)
18 // INT32-DAG: fir.unboxchar [[B1]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1>>, i64)
19 // INT64-DAG: [[B0:%[0-9]+]] = fir.emboxchar [[ARG1]], [[ARG3]] : (!fir.ref<!fir.char<1,?>>, i64) -> !fir.boxchar<1>
20 // INT64-DAG: [[B1:%[0-9]+]] = fir.emboxchar [[ARG0]], [[ARG2]] : (!fir.ref<!fir.char<1,?>>, i64) -> !fir.boxchar<1>
21 // INT64-DAG: fir.unboxchar [[B0]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1>>, i64)
22 // INT64-DAG: fir.unboxchar [[B1]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1>>, i64)
23 %1:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1>>, i64)
24 %2:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1>>, i64)
25 %3 = arith.addi %1#1, %2#1 : i64
29 // Test that we rewrite the signatures and bodies of functions that return a
31 // INT32-LABEL: @boxcharsret
32 // INT32-SAME: ([[ARG0:%[0-9A-Za-z]+]]: !fir.ref<!fir.char<1,?>> {llvm.sret = !fir.char<1,?>}, [[ARG1:%[0-9A-Za-z]+]]: i32, [[ARG2:%[0-9A-Za-z]+]]: !fir.ref<!fir.char<1,?>>, [[ARG3:%[0-9A-Za-z]+]]: i32)
33 // INT64-LABEL: @boxcharsret
34 // INT64-SAME: ([[ARG0:%[0-9A-Za-z]+]]: !fir.ref<!fir.char<1,?>> {llvm.sret = !fir.char<1,?>}, [[ARG1:%[0-9A-Za-z]+]]: i64, [[ARG2:%[0-9A-Za-z]+]]: !fir.ref<!fir.char<1,?>>, [[ARG3:%[0-9A-Za-z]+]]: i64)
35 func.func @boxcharsret(%arg0 : !fir.boxchar<1> {llvm.sret = !fir.char<1,?>}, %arg1 : !fir.boxchar<1>) {
36 // INT32-DAG: [[B0:%[0-9]+]] = fir.emboxchar [[ARG0]], [[ARG1]] : (!fir.ref<!fir.char<1,?>>, i32) -> !fir.boxchar<1>
37 // INT32-DAG: [[B1:%[0-9]+]] = fir.emboxchar [[ARG2]], [[ARG3]] : (!fir.ref<!fir.char<1,?>>, i32) -> !fir.boxchar<1>
38 // INT32-DAG: fir.unboxchar [[B0]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.array<?x!fir.char<1>>>, i64)
39 // INT32-DAG: fir.unboxchar [[B1]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.array<?x!fir.char<1>>>, i64)
40 // INT64-DAG: [[B0:%[0-9]+]] = fir.emboxchar [[ARG0]], [[ARG1]] : (!fir.ref<!fir.char<1,?>>, i64) -> !fir.boxchar<1>
41 // INT64-DAG: [[B1:%[0-9]+]] = fir.emboxchar [[ARG2]], [[ARG3]] : (!fir.ref<!fir.char<1,?>>, i64) -> !fir.boxchar<1>
42 // INT64-DAG: fir.unboxchar [[B0]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.array<?x!fir.char<1>>>, i64)
43 // INT64-DAG: fir.unboxchar [[B1]] : (!fir.boxchar<1>) -> (!fir.ref<!fir.array<?x!fir.char<1>>>, i64)
44 %1:2 = fir.unboxchar %arg0 : (!fir.boxchar<1>) -> (!fir.ref<!fir.array<?x!fir.char<1>>>, i64)
45 %2:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref<!fir.array<?x!fir.char<1>>>, i64)
46 %c0 = arith.constant 0 : index
47 %c1 = arith.constant 1 : index
48 %3 = fir.convert %1#1 : (i64) -> index
49 %last = arith.subi %3, %c1 : index
50 fir.do_loop %i = %c0 to %last step %c1 {
51 %in_pos = fir.coordinate_of %2#0, %i : (!fir.ref<!fir.array<?x!fir.char<1>>>, index) -> !fir.ref<!fir.char<1>>
52 %out_pos = fir.coordinate_of %1#0, %i : (!fir.ref<!fir.array<?x!fir.char<1>>>, index) -> !fir.ref<!fir.char<1>>
53 %ch = fir.load %in_pos : !fir.ref<!fir.char<1>>
54 fir.store %ch to %out_pos : !fir.ref<!fir.char<1>>
59 // Test that we rewrite the signatures of functions with a sret parameter and
60 // several other parameters.
61 // INT32-LABEL: @boxcharmultiple
62 // INT32-SAME: ({{%[0-9A-Za-z]+}}: !fir.ref<!fir.char<1,?>> {llvm.sret = !fir.char<1,?>}, {{%[0-9A-Za-z]+}}: i32, {{%[0-9A-Za-z]+}}: !fir.ref<!fir.char<1,?>>, {{%[0-9A-Za-z]+}}: !fir.ref<!fir.char<1,?>>, {{%[0-9A-Za-z]+}}: i32, {{%[0-9A-Za-z]+}}: i32)
63 // INT64-LABEL: @boxcharmultiple
64 // INT64-SAME: ({{%[0-9A-Za-z]+}}: !fir.ref<!fir.char<1,?>> {llvm.sret = !fir.char<1,?>}, {{%[0-9A-Za-z]+}}: i64, {{%[0-9A-Za-z]+}}: !fir.ref<!fir.char<1,?>>, {{%[0-9A-Za-z]+}}: !fir.ref<!fir.char<1,?>>, {{%[0-9A-Za-z]+}}: i64, {{%[0-9A-Za-z]+}}: i64)
65 func.func @boxcharmultiple(%arg0 : !fir.boxchar<1> {llvm.sret = !fir.char<1,?>}, %arg1 : !fir.boxchar<1>, %arg2 : !fir.boxchar<1>) {
69 // Test that we rewrite calls to functions that take boxchar arguments.
70 // INT32-LABEL: @boxcharcallee(!fir.ref<!fir.char<1,?>>, i32)
71 // INT64-LABEL: @boxcharcallee(!fir.ref<!fir.char<1,?>>, i64)
72 func.func private @boxcharcallee(%x : !fir.boxchar<1>)
76 func.func @boxchararg() {
77 %1 = fir.address_of (@name) : !fir.ref<!fir.char<1,9>>
78 %2 = arith.constant 9 : i64
79 %3 = fir.convert %1 : (!fir.ref<!fir.char<1,9>>) -> !fir.ref<!fir.char<1,?>>
80 // INT32: [[B:%[0-9A-Za-z]+]] = fir.emboxchar {{.*}} : (!fir.ref<!fir.char<1,?>>, i64) -> !fir.boxchar<1>
81 // INT32: [[U:%[0-9A-Za-z]+]]:2 = fir.unboxchar [[B]] : (!fir.boxchar<1>) ->
82 // (!fir.ref<!fir.char<1, ?>>, i32)
83 // INT64: [[B:%[0-9A-Za-z]+]] = fir.emboxchar {{.*}} : (!fir.ref<!fir.char<1,?>>, i64) -> !fir.boxchar<1>
84 // INT64: [[U:%[0-9A-Za-z]+]]:2 = fir.unboxchar [[B]] : (!fir.boxchar<1>) ->
85 // (!fir.ref<!fir.char<1, ?>>, i64)
86 %4 = fir.emboxchar %3, %2 : (!fir.ref<!fir.char<1,?>>, i64) -> !fir.boxchar<1>
87 // INT32: fir.call @boxcharcallee([[U]]#0, [[U]]#1) : (!fir.ref<!fir.char<1,?>>, i32) -> ()
88 // INT64: fir.call @boxcharcallee([[U]]#0, [[U]]#1) : (!fir.ref<!fir.char<1,?>>, i64) -> ()
89 fir.call @boxcharcallee(%4) : (!fir.boxchar<1>) -> ()
93 fir.global @name constant : !fir.char<1,9> {
94 %str = fir.string_lit "Your name"(9) : !fir.char<1,9>
96 fir.has_value %str : !fir.char<1,9>
99 // Test that we rewrite the fir.address_of operator
100 // INT32-LABEL: @addrof
101 // INT64-LABEL: @addrof
102 func.func @addrof() {
103 // INT32: {{.*}} = fir.address_of(@boxcharcallee) : (!fir.ref<!fir.char<1,?>>, i32) -> ()
104 // INT64: {{.*}} = fir.address_of(@boxcharcallee) : (!fir.ref<!fir.char<1,?>>, i64) -> ()
105 %f = fir.address_of(@boxcharcallee) : (!fir.boxchar<1>) -> ()