Files
clang-p2996/flang/test/HLFIR/assign-codegen-derived.fir
jeanPerier 87b2682ad2 [flang][hlfir] use fir.type_info to skip runtime call if nofinal is set (#68397)
HLFIR was always calling Destroy runtime when doing derived type scalar
assignments because the IR did not contain the info of whether
finalization was needed or not.

This info is now available in fir.type_info which allow skipping the
runtime call when not needed.

Also, when finalization is needed, simply use Assign runtime. This makes
no difference from a semantic point of view with the current code that
generated a call to Destroy and did the assignment inline, but if some
piece of runtime must be called anyway, it is simpler to just call
Assign that deals with everything.
2023-10-09 09:27:08 +02:00

30 lines
1.2 KiB
Plaintext

// Test hlfir.assign code generation to FIR of derived type requiring
// or not finalization.
// RUN: fir-opt %s -convert-hlfir-to-fir | FileCheck %s
!t_simple = !fir.type<simple{i:i32}>
fir.type_info @simple noinit nodestroy nofinal : !t_simple
func.func @test_simple(%a: !fir.ref<!t_simple>, %b: !fir.ref<!t_simple>) {
hlfir.assign %b to %a : !fir.ref<!t_simple>, !fir.ref<!t_simple>
return
}
// CHECK-LABEL: func.func @test_simple(
// CHECK-NOT: Destroy
// CHECK: %[[VAL_1:.*]] = fir.coordinate_of %{{.*}}, %{{.*}} : (!fir.ref<!fir.type<simple{i:i32}>>, !fir.field) -> !fir.ref<i32>
// CHECK: %[[VAL_3:.*]] = fir.coordinate_of %{{.*}}, %{{.*}} : (!fir.ref<!fir.type<simple{i:i32}>>, !fir.field) -> !fir.ref<i32>
// CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_1]] : !fir.ref<i32>
// CHECK: fir.store %[[VAL_4]] to %[[VAL_3]] : !fir.ref<i32>
!t_with_final = !fir.type<with_final{i:i32}>
fir.type_info @with_final noinit : !t_with_final
func.func @test_with_final(%a: !fir.ref<!t_with_final>, %b: !fir.ref<!t_with_final>) {
hlfir.assign %b to %a : !fir.ref<!t_with_final>, !fir.ref<!t_with_final>
return
}
// CHECK-LABEL: func.func @test_with_final(
// CHECK: fir.call @_FortranAAssign