60 lines · plain
1// Test that bind_c derived type results are not moved to a hidden argument2// by the abstract-result pass. They will be dealt with according to the C3// struct returning ABI for the target in the target-rewrite pass.4// RUN: fir-opt %s --abstract-result | FileCheck %s5 6!t = !fir.type<t{i:f32, j: i32, k: f32}>7!cptr = !fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>8 9func.func private @foo() -> !t attributes {fir.proc_attrs = #fir.proc_attrs<bind_c>}10 11func.func @test_call(%x: !fir.ref<!t>) {12 %0 = fir.call @foo() proc_attrs<bind_c> : () -> !t13 fir.save_result %0 to %x : !t, !fir.ref<!t>14 return15}16 17func.func @test_addr_of() -> (() -> !t) {18 %0 = fir.address_of(@foo) : () -> !t19 return %0 : () -> !t20}21 22func.func @test_dispatch(%x: !fir.ref<!t>, %y : !fir.class<!fir.type<somet>>) {23 %0 = fir.dispatch "bar"(%y : !fir.class<!fir.type<somet>>) (%y : !fir.class<!fir.type<somet>>) -> !t proc_attrs<bind_c> {pass_arg_pos = 0 : i32}24 fir.save_result %0 to %x : !t, !fir.ref<!t>25 return26}27 28 29func.func private @return_cptr() -> !cptr attributes {fir.proc_attrs = #fir.proc_attrs<bind_c>}30func.func @test_return_cptr(%x: !fir.ref<!cptr>) {31 %0 = fir.call @return_cptr() proc_attrs<bind_c> : () -> !cptr32 fir.save_result %0 to %x : !cptr, !fir.ref<!cptr>33 return34}35 36 37// CHECK-LABEL: func.func @test_call(38// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<t{i:f32,j:i32,k:f32}>>) {39// CHECK: %[[VAL_1:.*]] = fir.call @foo() proc_attrs<bind_c> : () -> !fir.type<t{i:f32,j:i32,k:f32}>40// CHECK: fir.store %[[VAL_1]] to %[[VAL_0]] : !fir.ref<!fir.type<t{i:f32,j:i32,k:f32}>>41// CHECK: return42// CHECK: }43// CHECK-LABEL: func.func @test_addr_of() -> (() -> !fir.type<t{i:f32,j:i32,k:f32}>) {44// CHECK: %[[VAL_0:.*]] = fir.address_of(@foo) : () -> !fir.type<t{i:f32,j:i32,k:f32}>45// CHECK: return %[[VAL_0]] : () -> !fir.type<t{i:f32,j:i32,k:f32}>46// CHECK: }47// CHECK-LABEL: func.func @test_dispatch(48// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<t{i:f32,j:i32,k:f32}>>,49// CHECK-SAME: %[[VAL_1:.*]]: !fir.class<!fir.type<somet>>) {50// CHECK: %[[VAL_2:.*]] = fir.dispatch "bar"(%[[VAL_1]] : !fir.class<!fir.type<somet>>) (%[[VAL_1]] : !fir.class<!fir.type<somet>>) -> !fir.type<t{i:f32,j:i32,k:f32}> proc_attrs <bind_c> {pass_arg_pos = 0 : i32}51// CHECK: fir.store %[[VAL_2]] to %[[VAL_0]] : !fir.ref<!fir.type<t{i:f32,j:i32,k:f32}>>52// CHECK: return53// CHECK: }54// CHECK-LABEL: func.func @test_return_cptr(55// CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>) {56// CHECK: %[[VAL_1:.*]] = fir.call @return_cptr() : () -> !fir.ref<none>57// CHECK: %[[VAL_3:.*]] = fir.coordinate_of %[[VAL_0]], __address : (!fir.ref<!fir.type<_QM__fortran_builtinsT__builtin_c_ptr{__address:i64}>>) -> !fir.ref<i64>58// CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_1]] : (!fir.ref<none>) -> i6459// CHECK: fir.store %[[VAL_4]] to %[[VAL_3]] : !fir.ref<i64>60