1 // Test rewrite of character procedure pointer tuple argument to two different
2 // arguments: one for the function address, and one for the length. The length
3 // argument is added after other characters.
4 // RUN: fir-opt --target-rewrite="target=x86_64-unknown-linux-gnu" %s | FileCheck %s
6 // CHECK: func private @takes_char_proc(() -> () {fir.char_proc}, i64)
7 func.func private @takes_char_proc(tuple<() -> (), i64> {fir.char_proc})
9 func.func private @takes_char(!fir.boxchar<1>)
10 func.func private @char_proc(!fir.ref<!fir.char<1,7>>, index) -> !fir.boxchar<1>
12 func.func @_QPcst_len() {
13 %0 = fir.address_of(@char_proc) : (!fir.ref<!fir.char<1,7>>, index) -> !fir.boxchar<1>
14 %c7_i64 = arith.constant 7 : i64
15 %1 = fir.convert %0 : ((!fir.ref<!fir.char<1,7>>, index) -> !fir.boxchar<1>) -> (() -> ())
16 %2 = fir.undefined tuple<() -> (), i64>
17 %3 = fir.insert_value %2, %1, [0 : index] : (tuple<() -> (), i64>, () -> ()) -> tuple<() -> (), i64>
18 %4 = fir.insert_value %3, %c7_i64, [1 : index] : (tuple<() -> (), i64>, i64) -> tuple<() -> (), i64>
20 // CHECK: %[[PROC_ADDR:.*]] = fir.extract_value %{{.*}}, [0 : index] : (tuple<() -> (), i64>) -> (() -> ())
21 // CHECK: %[[LEN:.*]] = fir.extract_value %{{.*}}, [1 : index] : (tuple<() -> (), i64>) -> i64
22 // CHECK: fir.call @takes_char_proc(%[[PROC_ADDR]], %[[LEN]]) : (() -> (), i64) -> ()
23 fir.call @takes_char_proc(%4) : (tuple<() -> (), i64>) -> ()
27 // CHECK: func @test_dummy_proc_that_takes_dummy_char_proc(
28 // CHECK-SAME: %[[ARG0:.*]]: () -> ()) {
29 func.func @test_dummy_proc_that_takes_dummy_char_proc(%arg0: () -> ()) {
30 %0 = fir.address_of(@char_proc) : (!fir.ref<!fir.char<1,7>>, index) -> !fir.boxchar<1>
31 %c7_i64 = arith.constant 7 : i64
32 %1 = fir.convert %0 : ((!fir.ref<!fir.char<1,7>>, index) -> !fir.boxchar<1>) -> (() -> ())
33 %2 = fir.undefined tuple<() -> (), i64>
34 %3 = fir.insert_value %2, %1, [0 : index] : (tuple<() -> (), i64>, () -> ()) -> tuple<() -> (), i64>
35 %4 = fir.insert_value %3, %c7_i64, [1 : index] : (tuple<() -> (), i64>, i64) -> tuple<() -> (), i64>
36 %5 = fir.convert %arg0 : (() -> ()) -> ((tuple<() -> (), i64>) -> ())
38 // CHECK: %[[ARG_CAST:.*]] = fir.convert %[[ARG0]] : (() -> ()) -> ((() -> (), i64) -> ())
39 // CHECK: %[[PROC_ADDR:.*]] = fir.extract_value %4, [0 : index] : (tuple<() -> (), i64>) -> (() -> ())
40 // CHECK: %[[PROC_LEN:.*]] = fir.extract_value %4, [1 : index] : (tuple<() -> (), i64>) -> i64
41 // CHECK: fir.call %[[ARG_CAST]](%[[PROC_ADDR]], %[[PROC_LEN]]) : (() -> (), i64) -> ()
42 fir.call %5(%4) : (tuple<() -> (), i64>) -> ()
46 // CHECK: func @takes_dummy_char_proc_impl(
47 // CHECK-SAME: %[[PROC_ADDR:.*]]: () -> () {fir.char_proc},
48 // CHECK-SAME: %[[C_ADDR:.*]]: !fir.ref<!fir.char<1,?>>,
49 // CHECK-SAME: %[[PROC_LEN:.*]]: i64,
50 // CHECK-SAME: %[[C_LEN:.*]]: i64) {
51 func.func @takes_dummy_char_proc_impl(%arg0: tuple<() -> (), i64> {fir.char_proc}, %arg1: !fir.boxchar<1>) {
52 // CHECK: %[[UNDEF:.*]] = fir.undefined tuple<() -> (), i64>
53 // CHECK: %[[TUPLE0:.*]] = fir.insert_value %[[UNDEF]], %[[PROC_ADDR]], [0 : index] : (tuple<() -> (), i64>, () -> ()) -> tuple<() -> (), i64>
54 // CHECK: %[[TUPLE1:.*]] = fir.insert_value %[[TUPLE0]], %[[PROC_LEN]], [1 : index] : (tuple<() -> (), i64>, i64) -> tuple<() -> (), i64>
55 %0 = fir.alloca !fir.char<1,7> {bindc_name = ".result"}
56 %1:2 = fir.unboxchar %arg1 : (!fir.boxchar<1>) -> (!fir.ref<!fir.char<1,?>>, index)
57 %c5 = arith.constant 5 : index
58 %2 = fir.emboxchar %1#0, %c5 : (!fir.ref<!fir.char<1,?>>, index) -> !fir.boxchar<1>
59 %3 = fir.extract_value %arg0, [0 : index] : (tuple<() -> (), i64>) -> (() -> ())
60 %c7_i64 = arith.constant 7 : i64
61 %4 = fir.convert %c7_i64 : (i64) -> index
62 %6 = fir.convert %3 : (() -> ()) -> ((!fir.ref<!fir.char<1,7>>, index, !fir.boxchar<1>) -> !fir.boxchar<1>)
63 %7 = fir.call %6(%0, %4, %2) : (!fir.ref<!fir.char<1,7>>, index, !fir.boxchar<1>) -> !fir.boxchar<1>
64 %8 = fir.convert %0 : (!fir.ref<!fir.char<1,7>>) -> !fir.ref<!fir.char<1,?>>
65 %9 = fir.emboxchar %8, %4 : (!fir.ref<!fir.char<1,?>>, index) -> !fir.boxchar<1>
66 fir.call @takes_char(%9) : (!fir.boxchar<1>) -> ()