diff --git a/flang/test/Lower/Intrinsics/btest.f90 b/flang/test/Lower/Intrinsics/btest.f90 index b10850ef0b5e6..bc7475364f102 100644 --- a/flang/test/Lower/Intrinsics/btest.f90 +++ b/flang/test/Lower/Intrinsics/btest.f90 @@ -1,17 +1,20 @@ -! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s +! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s -! CHECK-LABEL: btest_test +! CHECK-LABEL: _QPbtest_test function btest_test(i, j) logical btest_test - ! CHECK-DAG: %[[result:[0-9]+]] = fir.alloca !fir.logical<4> {bindc_name = "btest_test" - ! CHECK-DAG: %[[i:[0-9]+]] = fir.load %arg0 : !fir.ref - ! CHECK-DAG: %[[j:[0-9]+]] = fir.load %arg1 : !fir.ref + ! CHECK-DAG: %[[result_alloca:.*]] = fir.alloca !fir.logical<4> {bindc_name = "btest_test" + ! CHECK-DAG: %[[result:.*]]:2 = hlfir.declare %[[result_alloca]] {uniq_name = "_QFbtest_testEbtest_test"} : (!fir.ref>) -> (!fir.ref>, !fir.ref>) + ! CHECK-DAG: %[[i_decl:.*]]:2 = hlfir.declare %arg0 {{.*}} {uniq_name = "_QFbtest_testEi"} : (!fir.ref, !fir.dscope) -> (!fir.ref, !fir.ref) + ! CHECK-DAG: %[[j_decl:.*]]:2 = hlfir.declare %arg1 {{.*}} {uniq_name = "_QFbtest_testEj"} : (!fir.ref, !fir.dscope) -> (!fir.ref, !fir.ref) + ! CHECK-DAG: %[[i:.*]] = fir.load %[[i_decl]]#0 : !fir.ref + ! CHECK-DAG: %[[j:.*]] = fir.load %[[j_decl]]#0 : !fir.ref ! CHECK-DAG: %[[VAL_5:.*]] = arith.shrui %[[i]], %[[j]] : i32 ! CHECK-DAG: %[[VAL_6:.*]] = arith.constant 1 : i32 ! CHECK: %[[VAL_7:.*]] = arith.andi %[[VAL_5]], %[[VAL_6]] : i32 ! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (i32) -> !fir.logical<4> - ! CHECK: fir.store %[[VAL_8]] to %[[result]] : !fir.ref> - ! CHECK: %[[VAL_9:.*]] = fir.load %[[result]] : !fir.ref> + ! CHECK: hlfir.assign %[[VAL_8]] to %[[result]]#0 : !fir.logical<4>, !fir.ref> + ! CHECK: %[[VAL_9:.*]] = fir.load %[[result]]#0 : !fir.ref> ! CHECK: return %[[VAL_9]] : !fir.logical<4> btest_test = btest(i, j) end diff --git a/flang/test/Lower/Intrinsics/c_associated.f90 b/flang/test/Lower/Intrinsics/c_associated.f90 index 3956957853372..479a408332777 100644 --- a/flang/test/Lower/Intrinsics/c_associated.f90 +++ b/flang/test/Lower/Intrinsics/c_associated.f90 @@ -1,37 +1,40 @@ -! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s -! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir %s -o - | FileCheck %s +! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s ! Test intrinsic module procedure c_associated ! CHECK-LABEL: func.func @_QPtest_c_ptr( -! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref> {fir.bindc_name = "cptr1"}, -! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref> {fir.bindc_name = "cptr2"}) { -! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.logical<4> {bindc_name = "z1", uniq_name = "_QFtest_c_ptrEz1"} -! CHECK: %[[VAL_3:.*]] = fir.alloca !fir.logical<4> {bindc_name = "z2", uniq_name = "_QFtest_c_ptrEz2"} -! CHECK: %[[VAL_5:.*]] = fir.coordinate_of %[[VAL_0]], __address : (!fir.ref>) -> !fir.ref +! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref> {fir.bindc_name = "cptr1"}, +! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref> {fir.bindc_name = "cptr2"}) { +! CHECK-DAG: %[[VAL_CPTR1:.*]]:2 = hlfir.declare %[[VAL_0]] {{.*}} {uniq_name = "_QFtest_c_ptrEcptr1"} +! CHECK-DAG: %[[VAL_CPTR2:.*]]:2 = hlfir.declare %[[VAL_1]] {{.*}} {uniq_name = "_QFtest_c_ptrEcptr2"} +! CHECK-DAG: %[[VAL_Z1_ALLOCA:.*]] = fir.alloca !fir.logical<4> {bindc_name = "z1", uniq_name = "_QFtest_c_ptrEz1"} +! CHECK-DAG: %[[VAL_Z1:.*]]:2 = hlfir.declare %[[VAL_Z1_ALLOCA]] {uniq_name = "_QFtest_c_ptrEz1"} +! CHECK-DAG: %[[VAL_Z2_ALLOCA:.*]] = fir.alloca !fir.logical<4> {bindc_name = "z2", uniq_name = "_QFtest_c_ptrEz2"} +! CHECK-DAG: %[[VAL_Z2:.*]]:2 = hlfir.declare %[[VAL_Z2_ALLOCA]] {uniq_name = "_QFtest_c_ptrEz2"} +! CHECK: %[[VAL_5:.*]] = fir.coordinate_of %[[VAL_CPTR1]]#0, __address : (!fir.ref>) -> !fir.ref ! CHECK: %[[VAL_6:.*]] = fir.load %[[VAL_5]] : !fir.ref ! CHECK: %[[VAL_7:.*]] = arith.constant 0 : i64 ! CHECK: %[[VAL_8:.*]] = arith.cmpi ne, %[[VAL_6]], %[[VAL_7]] : i64 ! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_8]] : (i1) -> !fir.logical<4> -! CHECK: fir.store %[[VAL_9]] to %[[VAL_2]] : !fir.ref> -! CHECK: %[[VAL_11:.*]] = fir.coordinate_of %[[VAL_0]], __address : (!fir.ref>) -> !fir.ref +! CHECK: hlfir.assign %[[VAL_9]] to %[[VAL_Z1]]#0 : !fir.logical<4>, !fir.ref> +! CHECK: %[[VAL_11:.*]] = fir.coordinate_of %[[VAL_CPTR1]]#0, __address : (!fir.ref>) -> !fir.ref ! CHECK: %[[VAL_12:.*]] = fir.load %[[VAL_11]] : !fir.ref ! CHECK: %[[VAL_13:.*]] = arith.constant 0 : i64 ! CHECK: %[[VAL_14:.*]] = arith.cmpi ne, %[[VAL_12]], %[[VAL_13]] : i64 -! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_1]] : (!fir.ref>) -> i64 +! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_CPTR2]]#0 : (!fir.ref>) -> i64 ! CHECK: %[[VAL_16:.*]] = arith.constant 0 : i64 ! CHECK: %[[VAL_17:.*]] = arith.cmpi eq, %[[VAL_15]], %[[VAL_16]] : i64 ! CHECK: %[[VAL_18:.*]] = fir.if %[[VAL_17]] -> (i1) { ! CHECK: fir.result %[[VAL_14]] : i1 ! CHECK: } else { -! CHECK: %[[VAL_20:.*]] = fir.coordinate_of %[[VAL_1]], __address : (!fir.ref>) -> !fir.ref +! CHECK: %[[VAL_20:.*]] = fir.coordinate_of %[[VAL_CPTR2]]#0, __address : (!fir.ref>) -> !fir.ref ! CHECK: %[[VAL_21:.*]] = fir.load %[[VAL_20]] : !fir.ref ! CHECK: %[[VAL_22:.*]] = arith.cmpi eq, %[[VAL_12]], %[[VAL_21]] : i64 ! CHECK: %[[VAL_23:.*]] = arith.andi %[[VAL_14]], %[[VAL_22]] : i1 ! CHECK: fir.result %[[VAL_23]] : i1 ! CHECK: } -! CHECK: %[[VAL_24:.*]] = fir.convert %[[VAL_25:.*]] : (i1) -> !fir.logical<4> -! CHECK: fir.store %[[VAL_24]] to %[[VAL_3]] : !fir.ref> +! CHECK: %[[VAL_24:.*]] = fir.convert %[[VAL_18]] : (i1) -> !fir.logical<4> +! CHECK: hlfir.assign %[[VAL_24]] to %[[VAL_Z2]]#0 : !fir.logical<4>, !fir.ref> ! CHECK: return ! CHECK: } @@ -46,34 +49,38 @@ subroutine test_c_ptr(cptr1, cptr2) end ! CHECK-LABEL: func.func @_QPtest_c_funptr( -! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref> {fir.bindc_name = "cptr1"}, -! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref> {fir.bindc_name = "cptr2"}) { -! CHECK: %[[VAL_2:.*]] = fir.alloca !fir.logical<4> {bindc_name = "z1", uniq_name = "_QFtest_c_funptrEz1"} -! CHECK: %[[VAL_3:.*]] = fir.alloca !fir.logical<4> {bindc_name = "z2", uniq_name = "_QFtest_c_funptrEz2"} -! CHECK: %[[VAL_5:.*]] = fir.coordinate_of %[[VAL_0]], __address : (!fir.ref>) -> !fir.ref +! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref> {fir.bindc_name = "cptr1"}, +! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref> {fir.bindc_name = "cptr2"}) { +! CHECK-DAG: %[[VAL_CPTR1:.*]]:2 = hlfir.declare %[[VAL_0]] {{.*}} {uniq_name = "_QFtest_c_funptrEcptr1"} +! CHECK-DAG: %[[VAL_CPTR2:.*]]:2 = hlfir.declare %[[VAL_1]] {{.*}} {uniq_name = "_QFtest_c_funptrEcptr2"} +! CHECK-DAG: %[[VAL_Z1_ALLOCA:.*]] = fir.alloca !fir.logical<4> {bindc_name = "z1", uniq_name = "_QFtest_c_funptrEz1"} +! CHECK-DAG: %[[VAL_Z1:.*]]:2 = hlfir.declare %[[VAL_Z1_ALLOCA]] {uniq_name = "_QFtest_c_funptrEz1"} +! CHECK-DAG: %[[VAL_Z2_ALLOCA:.*]] = fir.alloca !fir.logical<4> {bindc_name = "z2", uniq_name = "_QFtest_c_funptrEz2"} +! CHECK-DAG: %[[VAL_Z2:.*]]:2 = hlfir.declare %[[VAL_Z2_ALLOCA]] {uniq_name = "_QFtest_c_funptrEz2"} +! CHECK: %[[VAL_5:.*]] = fir.coordinate_of %[[VAL_CPTR1]]#0, __address : (!fir.ref>) -> !fir.ref ! CHECK: %[[VAL_6:.*]] = fir.load %[[VAL_5]] : !fir.ref ! CHECK: %[[VAL_7:.*]] = arith.constant 0 : i64 ! CHECK: %[[VAL_8:.*]] = arith.cmpi ne, %[[VAL_6]], %[[VAL_7]] : i64 ! CHECK: %[[VAL_9:.*]] = fir.convert %[[VAL_8]] : (i1) -> !fir.logical<4> -! CHECK: fir.store %[[VAL_9]] to %[[VAL_2]] : !fir.ref> -! CHECK: %[[VAL_11:.*]] = fir.coordinate_of %[[VAL_0]], __address : (!fir.ref>) -> !fir.ref +! CHECK: hlfir.assign %[[VAL_9]] to %[[VAL_Z1]]#0 : !fir.logical<4>, !fir.ref> +! CHECK: %[[VAL_11:.*]] = fir.coordinate_of %[[VAL_CPTR1]]#0, __address : (!fir.ref>) -> !fir.ref ! CHECK: %[[VAL_12:.*]] = fir.load %[[VAL_11]] : !fir.ref ! CHECK: %[[VAL_13:.*]] = arith.constant 0 : i64 ! CHECK: %[[VAL_14:.*]] = arith.cmpi ne, %[[VAL_12]], %[[VAL_13]] : i64 -! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_1]] : (!fir.ref>) -> i64 +! CHECK: %[[VAL_15:.*]] = fir.convert %[[VAL_CPTR2]]#0 : (!fir.ref>) -> i64 ! CHECK: %[[VAL_16:.*]] = arith.constant 0 : i64 ! CHECK: %[[VAL_17:.*]] = arith.cmpi eq, %[[VAL_15]], %[[VAL_16]] : i64 ! CHECK: %[[VAL_18:.*]] = fir.if %[[VAL_17]] -> (i1) { ! CHECK: fir.result %[[VAL_14]] : i1 ! CHECK: } else { -! CHECK: %[[VAL_20:.*]] = fir.coordinate_of %[[VAL_1]], __address : (!fir.ref>) -> !fir.ref +! CHECK: %[[VAL_20:.*]] = fir.coordinate_of %[[VAL_CPTR2]]#0, __address : (!fir.ref>) -> !fir.ref ! CHECK: %[[VAL_21:.*]] = fir.load %[[VAL_20]] : !fir.ref ! CHECK: %[[VAL_22:.*]] = arith.cmpi eq, %[[VAL_12]], %[[VAL_21]] : i64 ! CHECK: %[[VAL_23:.*]] = arith.andi %[[VAL_14]], %[[VAL_22]] : i1 ! CHECK: fir.result %[[VAL_23]] : i1 ! CHECK: } -! CHECK: %[[VAL_24:.*]] = fir.convert %[[VAL_25:.*]] : (i1) -> !fir.logical<4> -! CHECK: fir.store %[[VAL_24]] to %[[VAL_3]] : !fir.ref> +! CHECK: %[[VAL_24:.*]] = fir.convert %[[VAL_18]] : (i1) -> !fir.logical<4> +! CHECK: hlfir.assign %[[VAL_24]] to %[[VAL_Z2]]#0 : !fir.logical<4>, !fir.ref> ! CHECK: return ! CHECK: } @@ -88,48 +95,54 @@ subroutine test_c_funptr(cptr1, cptr2) end ! CHECK-LABEL: func.func @_QPtest_optional_argument( -! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref> {fir.bindc_name = "cptr1"}, -! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref> {fir.bindc_name = "cptr2", fir.optional}, -! CHECK-SAME: %[[VAL_2:.*]]: !fir.ref> {fir.bindc_name = "cfunptr1"}, -! CHECK-SAME: %[[VAL_3:.*]]: !fir.ref> {fir.bindc_name = "cfunptr2", fir.optional}) { -! CHECK: %[[VAL_4:.*]] = fir.alloca !fir.logical<4> {bindc_name = "z1", uniq_name = "_QFtest_optional_argumentEz1"} -! CHECK: %[[VAL_5:.*]] = fir.alloca !fir.logical<4> {bindc_name = "z2", uniq_name = "_QFtest_optional_argumentEz2"} -! CHECK: %[[VAL_7:.*]] = fir.coordinate_of %[[VAL_0]], __address : (!fir.ref>) -> !fir.ref +! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref> {fir.bindc_name = "cptr1"}, +! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref> {fir.bindc_name = "cptr2", fir.optional}, +! CHECK-SAME: %[[VAL_2:.*]]: !fir.ref> {fir.bindc_name = "cfunptr1"}, +! CHECK-SAME: %[[VAL_3:.*]]: !fir.ref> {fir.bindc_name = "cfunptr2", fir.optional}) { +! CHECK-DAG: %[[VAL_CPTR1:.*]]:2 = hlfir.declare %[[VAL_0]] {{.*}} {uniq_name = "_QFtest_optional_argumentEcptr1"} +! CHECK-DAG: %[[VAL_CPTR2:.*]]:2 = hlfir.declare %[[VAL_1]] {{.*}} {fortran_attrs = #fir.var_attrs, uniq_name = "_QFtest_optional_argumentEcptr2"} +! CHECK-DAG: %[[VAL_CFUNPTR1:.*]]:2 = hlfir.declare %[[VAL_2]] {{.*}} {uniq_name = "_QFtest_optional_argumentEcfunptr1"} +! CHECK-DAG: %[[VAL_CFUNPTR2:.*]]:2 = hlfir.declare %[[VAL_3]] {{.*}} {fortran_attrs = #fir.var_attrs, uniq_name = "_QFtest_optional_argumentEcfunptr2"} +! CHECK-DAG: %[[VAL_Z1_ALLOCA:.*]] = fir.alloca !fir.logical<4> {bindc_name = "z1", uniq_name = "_QFtest_optional_argumentEz1"} +! CHECK-DAG: %[[VAL_Z1:.*]]:2 = hlfir.declare %[[VAL_Z1_ALLOCA]] {uniq_name = "_QFtest_optional_argumentEz1"} +! CHECK-DAG: %[[VAL_Z2_ALLOCA:.*]] = fir.alloca !fir.logical<4> {bindc_name = "z2", uniq_name = "_QFtest_optional_argumentEz2"} +! CHECK-DAG: %[[VAL_Z2:.*]]:2 = hlfir.declare %[[VAL_Z2_ALLOCA]] {uniq_name = "_QFtest_optional_argumentEz2"} +! CHECK: %[[VAL_7:.*]] = fir.coordinate_of %[[VAL_CPTR1]]#0, __address : (!fir.ref>) -> !fir.ref ! CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_7]] : !fir.ref ! CHECK: %[[VAL_9:.*]] = arith.constant 0 : i64 ! CHECK: %[[VAL_10:.*]] = arith.cmpi ne, %[[VAL_8]], %[[VAL_9]] : i64 -! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_1]] : (!fir.ref>) -> i64 +! CHECK: %[[VAL_11:.*]] = fir.convert %[[VAL_CPTR2]]#0 : (!fir.ref>) -> i64 ! CHECK: %[[VAL_12:.*]] = arith.constant 0 : i64 ! CHECK: %[[VAL_13:.*]] = arith.cmpi eq, %[[VAL_11]], %[[VAL_12]] : i64 ! CHECK: %[[VAL_14:.*]] = fir.if %[[VAL_13]] -> (i1) { ! CHECK: fir.result %[[VAL_10]] : i1 ! CHECK: } else { -! CHECK: %[[VAL_16:.*]] = fir.coordinate_of %[[VAL_1]], __address : (!fir.ref>) -> !fir.ref +! CHECK: %[[VAL_16:.*]] = fir.coordinate_of %[[VAL_CPTR2]]#0, __address : (!fir.ref>) -> !fir.ref ! CHECK: %[[VAL_17:.*]] = fir.load %[[VAL_16]] : !fir.ref ! CHECK: %[[VAL_18:.*]] = arith.cmpi eq, %[[VAL_8]], %[[VAL_17]] : i64 ! CHECK: %[[VAL_19:.*]] = arith.andi %[[VAL_10]], %[[VAL_18]] : i1 ! CHECK: fir.result %[[VAL_19]] : i1 ! CHECK: } -! CHECK: %[[VAL_20:.*]] = fir.convert %[[VAL_21:.*]] : (i1) -> !fir.logical<4> -! CHECK: fir.store %[[VAL_20]] to %[[VAL_4]] : !fir.ref> -! CHECK: %[[VAL_23:.*]] = fir.coordinate_of %[[VAL_2]], __address : (!fir.ref>) -> !fir.ref +! CHECK: %[[VAL_20:.*]] = fir.convert %[[VAL_14]] : (i1) -> !fir.logical<4> +! CHECK: hlfir.assign %[[VAL_20]] to %[[VAL_Z1]]#0 : !fir.logical<4>, !fir.ref> +! CHECK: %[[VAL_23:.*]] = fir.coordinate_of %[[VAL_CFUNPTR1]]#0, __address : (!fir.ref>) -> !fir.ref ! CHECK: %[[VAL_24:.*]] = fir.load %[[VAL_23]] : !fir.ref ! CHECK: %[[VAL_25:.*]] = arith.constant 0 : i64 ! CHECK: %[[VAL_26:.*]] = arith.cmpi ne, %[[VAL_24]], %[[VAL_25]] : i64 -! CHECK: %[[VAL_27:.*]] = fir.convert %[[VAL_3]] : (!fir.ref>) -> i64 +! CHECK: %[[VAL_27:.*]] = fir.convert %[[VAL_CFUNPTR2]]#0 : (!fir.ref>) -> i64 ! CHECK: %[[VAL_28:.*]] = arith.constant 0 : i64 ! CHECK: %[[VAL_29:.*]] = arith.cmpi eq, %[[VAL_27]], %[[VAL_28]] : i64 ! CHECK: %[[VAL_30:.*]] = fir.if %[[VAL_29]] -> (i1) { ! CHECK: fir.result %[[VAL_26]] : i1 ! CHECK: } else { -! CHECK: %[[VAL_32:.*]] = fir.coordinate_of %[[VAL_3]], __address : (!fir.ref>) -> !fir.ref +! CHECK: %[[VAL_32:.*]] = fir.coordinate_of %[[VAL_CFUNPTR2]]#0, __address : (!fir.ref>) -> !fir.ref ! CHECK: %[[VAL_33:.*]] = fir.load %[[VAL_32]] : !fir.ref ! CHECK: %[[VAL_34:.*]] = arith.cmpi eq, %[[VAL_24]], %[[VAL_33]] : i64 ! CHECK: %[[VAL_35:.*]] = arith.andi %[[VAL_26]], %[[VAL_34]] : i1 ! CHECK: fir.result %[[VAL_35]] : i1 ! CHECK: } -! CHECK: %[[VAL_36:.*]] = fir.convert %[[VAL_37:.*]] : (i1) -> !fir.logical<4> -! CHECK: fir.store %[[VAL_36]] to %[[VAL_5]] : !fir.ref> +! CHECK: %[[VAL_36:.*]] = fir.convert %[[VAL_30]] : (i1) -> !fir.logical<4> +! CHECK: hlfir.assign %[[VAL_36]] to %[[VAL_Z2]]#0 : !fir.logical<4>, !fir.ref> ! CHECK: return ! CHECK: } diff --git a/flang/test/Lower/Intrinsics/c_funloc.f90 b/flang/test/Lower/Intrinsics/c_funloc.f90 index 93be2215ffef4..21b3ddfa7c541 100644 --- a/flang/test/Lower/Intrinsics/c_funloc.f90 +++ b/flang/test/Lower/Intrinsics/c_funloc.f90 @@ -1,16 +1,21 @@ -! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s -! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir %s -o - | FileCheck %s +! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s ! Test intrinsic module procedure c_funloc ! CHECK-LABEL: func.func @_QPtest() { +! CHECK-DAG: %[[TMP_CPTR_ALLOCA:.*]] = fir.alloca !fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}> {bindc_name = "tmp_cptr", uniq_name = "_QFtestEtmp_cptr"} +! CHECK-DAG: %[[TMP_CPTR:.*]]:2 = hlfir.declare %[[TMP_CPTR_ALLOCA]] {uniq_name = "_QFtestEtmp_cptr"} ! CHECK: %[[VAL_1:.*]] = fir.address_of(@_QPfoo) : (!fir.ref) -> () -! CHECK: %[[VAL_2:.*]] = fir.emboxproc %[[VAL_1]] : ((!fir.ref) -> ()) -> !fir.boxproc<(!fir.ref) -> ()> -! CHECK: %[[VAL_3:.*]] = fir.alloca !fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}> -! CHECK-DAG: %[[VAL_4:.*]] = fir.box_addr %[[VAL_2]] : (!fir.boxproc<(!fir.ref) -> ()>) -> ((!fir.ref) -> ()) -! CHECK-DAG: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : ((!fir.ref) -> ()) -> i64 -! CHECK-DAG: %[[VAL_7:.*]] = fir.coordinate_of %[[VAL_3]], __address : (!fir.ref>) -> !fir.ref +! CHECK: %[[VAL_2:.*]] = fir.emboxproc %[[VAL_1]] : ((!fir.ref) -> ()) -> !fir.boxproc<() -> ()> +! CHECK: %[[RESULT_ALLOCA:.*]] = fir.alloca !fir.type<_QM__fortran_builtinsT__builtin_c_funptr{__address:i64}> +! CHECK: %[[VAL_7:.*]] = fir.coordinate_of %[[RESULT_ALLOCA]], __address : (!fir.ref>) -> !fir.ref +! CHECK: %[[VAL_4:.*]] = fir.box_addr %[[VAL_2]] : (!fir.boxproc<() -> ()>) -> (() -> ()) +! CHECK: %[[VAL_5:.*]] = fir.convert %[[VAL_4]] : (() -> ()) -> i64 ! CHECK: fir.store %[[VAL_5]] to %[[VAL_7]] : !fir.ref +! CHECK: %[[RESULT_DECL:.*]]:2 = hlfir.declare %[[RESULT_ALLOCA]] {uniq_name = ".tmp.intrinsic_result"} +! CHECK: %[[RESULT_EXPR:.*]] = hlfir.as_expr %[[RESULT_DECL]]#0 move %{{.*}} : (!fir.ref>, i1) -> !hlfir.expr> +! CHECK: hlfir.assign %[[RESULT_EXPR]] to %[[TMP_CPTR]]#0 : !hlfir.expr>, !fir.ref> +! CHECK: hlfir.destroy %[[RESULT_EXPR]] : !hlfir.expr> subroutine test() use iso_c_binding diff --git a/flang/test/Lower/Intrinsics/cmplx.f90 b/flang/test/Lower/Intrinsics/cmplx.f90 index 13da3efa33427..b3d832bf5ca36 100644 --- a/flang/test/Lower/Intrinsics/cmplx.f90 +++ b/flang/test/Lower/Intrinsics/cmplx.f90 @@ -3,23 +3,24 @@ ! a disassociated pointer, or an optional argument. ! CMPLX without such argument is re-written by the front-end as a ! complex constructor that is tested elsewhere. -! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s +! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s -! CHECK-LABEL: func @_QPcmplx_test_scalar_ptr( -! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref -! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref>> +! CHECK-LABEL: func.func @_QPcmplx_test_scalar_ptr( +! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref {fir.bindc_name = "x"}, %[[VAL_1:.*]]: !fir.ref>> {fir.bindc_name = "y"}) subroutine cmplx_test_scalar_ptr(x, y) real :: x real, pointer :: y print *, cmplx(x, y) -! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_0]] : !fir.ref -! CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_1]] : !fir.ref>> +! CHECK-DAG: %[[X:.*]]:2 = hlfir.declare %[[VAL_0]] +! CHECK-DAG: %[[Y:.*]]:2 = hlfir.declare %[[VAL_1]] +! CHECK: %[[VAL_8:.*]] = fir.load %[[Y]]#0 : !fir.ref>> ! CHECK: %[[VAL_9:.*]] = fir.box_addr %[[VAL_8]] : (!fir.box>) -> !fir.ptr ! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_9]] : (!fir.ptr) -> i64 ! CHECK: %[[VAL_11:.*]] = arith.constant 0 : i64 ! CHECK: %[[VAL_12:.*]] = arith.cmpi ne, %[[VAL_10]], %[[VAL_11]] : i64 +! CHECK: %[[VAL_7:.*]] = fir.load %[[X]]#0 : !fir.ref ! CHECK: %[[VAL_13:.*]] = fir.if %[[VAL_12]] -> (f32) { -! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_1]] : !fir.ref>> +! CHECK: %[[VAL_14:.*]] = fir.load %[[Y]]#0 : !fir.ref>> ! CHECK: %[[VAL_15:.*]] = fir.box_addr %[[VAL_14]] : (!fir.box>) -> !fir.ptr ! CHECK: %[[VAL_16:.*]] = fir.load %[[VAL_15]] : !fir.ptr ! CHECK: fir.result %[[VAL_16]] : f32 @@ -29,20 +30,21 @@ subroutine cmplx_test_scalar_ptr(x, y) ! CHECK: } ! CHECK: %[[VAL_18:.*]] = fir.undefined complex ! CHECK: %[[VAL_19:.*]] = fir.insert_value %[[VAL_18]], %[[VAL_7]], [0 : index] : (complex, f32) -> complex -! CHECK: fir.insert_value %[[VAL_19]], %[[VAL_21:.*]], [1 : index] : (complex, f32) -> complex +! CHECK: %[[VAL_20:.*]] = fir.insert_value %[[VAL_19]], %[[VAL_13]], [1 : index] : (complex, f32) -> complex end subroutine -! CHECK-LABEL: func @_QPcmplx_test_scalar_optional( -! CHECK-SAME: %[[VAL_0:[^:]*]]: !fir.ref -! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref +! CHECK-LABEL: func.func @_QPcmplx_test_scalar_optional( +! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref {fir.bindc_name = "x"}, %[[VAL_1:.*]]: !fir.ref {fir.bindc_name = "y", fir.optional}) subroutine cmplx_test_scalar_optional(x, y) real :: x real, optional :: y print *, cmplx(x, y) -! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_0]] : !fir.ref -! CHECK: %[[VAL_8:.*]] = fir.is_present %[[VAL_1]] : (!fir.ref) -> i1 +! CHECK-DAG: %[[X:.*]]:2 = hlfir.declare %[[VAL_0]] +! CHECK-DAG: %[[Y:.*]]:2 = hlfir.declare %[[VAL_1]] +! CHECK: %[[VAL_8:.*]] = fir.is_present %[[Y]]#0 : (!fir.ref) -> i1 +! CHECK: %[[VAL_7:.*]] = fir.load %[[X]]#0 : !fir.ref ! CHECK: %[[VAL_9:.*]] = fir.if %[[VAL_8]] -> (f32) { -! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_1]] : !fir.ref +! CHECK: %[[VAL_10:.*]] = fir.load %[[Y]]#0 : !fir.ref ! CHECK: fir.result %[[VAL_10]] : f32 ! CHECK: } else { ! CHECK: %[[VAL_11:.*]] = arith.constant 0.000000e+00 : f32 @@ -50,24 +52,25 @@ subroutine cmplx_test_scalar_optional(x, y) ! CHECK: } ! CHECK: %[[VAL_12:.*]] = fir.undefined complex ! CHECK: %[[VAL_13:.*]] = fir.insert_value %[[VAL_12]], %[[VAL_7]], [0 : index] : (complex, f32) -> complex -! CHECK: fir.insert_value %[[VAL_13]], %[[VAL_15:.*]], [1 : index] : (complex, f32) -> complex +! CHECK: %[[VAL_14:.*]] = fir.insert_value %[[VAL_13]], %[[VAL_9]], [1 : index] : (complex, f32) -> complex end subroutine -! CHECK-LABEL: func @_QPcmplx_test_scalar_alloc_optional( -! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref -! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref>> +! CHECK-LABEL: func.func @_QPcmplx_test_scalar_alloc_optional( +! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref {fir.bindc_name = "x"}, %[[VAL_1:.*]]: !fir.ref>> {fir.bindc_name = "y", fir.optional}) subroutine cmplx_test_scalar_alloc_optional(x, y) real :: x integer(8), allocatable, optional :: y print *, cmplx(x, y) -! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_0]] : !fir.ref -! CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_1]] : !fir.ref>> +! CHECK-DAG: %[[X:.*]]:2 = hlfir.declare %[[VAL_0]] +! CHECK-DAG: %[[Y:.*]]:2 = hlfir.declare %[[VAL_1]] +! CHECK: %[[VAL_8:.*]] = fir.load %[[Y]]#0 : !fir.ref>> ! CHECK: %[[VAL_9:.*]] = fir.box_addr %[[VAL_8]] : (!fir.box>) -> !fir.heap ! CHECK: %[[VAL_10:.*]] = fir.convert %[[VAL_9]] : (!fir.heap) -> i64 ! CHECK: %[[VAL_11:.*]] = arith.constant 0 : i64 ! CHECK: %[[VAL_12:.*]] = arith.cmpi ne, %[[VAL_10]], %[[VAL_11]] : i64 +! CHECK: %[[VAL_7:.*]] = fir.load %[[X]]#0 : !fir.ref ! CHECK: %[[VAL_13:.*]] = fir.if %[[VAL_12]] -> (i64) { -! CHECK: %[[VAL_14:.*]] = fir.load %[[VAL_1]] : !fir.ref>> +! CHECK: %[[VAL_14:.*]] = fir.load %[[Y]]#0 : !fir.ref>> ! CHECK: %[[VAL_15:.*]] = fir.box_addr %[[VAL_14]] : (!fir.box>) -> !fir.heap ! CHECK: %[[VAL_16:.*]] = fir.load %[[VAL_15]] : !fir.heap ! CHECK: fir.result %[[VAL_16]] : i64 @@ -75,15 +78,14 @@ subroutine cmplx_test_scalar_alloc_optional(x, y) ! CHECK: %[[VAL_17:.*]] = arith.constant 0 : i64 ! CHECK: fir.result %[[VAL_17]] : i64 ! CHECK: } -! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_19:.*]] : (i64) -> f32 +! CHECK: %[[VAL_18:.*]] = fir.convert %[[VAL_13]] : (i64) -> f32 ! CHECK: %[[VAL_20:.*]] = fir.undefined complex ! CHECK: %[[VAL_21:.*]] = fir.insert_value %[[VAL_20]], %[[VAL_7]], [0 : index] : (complex, f32) -> complex -! CHECK: fir.insert_value %[[VAL_21]], %[[VAL_18]], [1 : index] : (complex, f32) -> complex +! CHECK: %[[VAL_22:.*]] = fir.insert_value %[[VAL_21]], %[[VAL_18]], [1 : index] : (complex, f32) -> complex end subroutine -! CHECK-LABEL: func @_QPcmplx_test_pointer_result( -! CHECK-SAME: %[[VAL_0:[^:]*]]: !fir.ref -! CHECK-SAME: %[[VAL_1:.*]]: !fir.ref +! CHECK-LABEL: func.func @_QPcmplx_test_pointer_result( +! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref {fir.bindc_name = "x"}, %[[VAL_1:.*]]: !fir.ref {fir.bindc_name = "y"}) subroutine cmplx_test_pointer_result(x, y) real :: x interface @@ -92,15 +94,18 @@ function return_pointer() end function end interface print *, cmplx(x, return_pointer()) -! CHECK: %[[VAL_9:.*]] = fir.call @_QPreturn_pointer() {{.*}}: () -> !fir.box> -! CHECK: fir.save_result %[[VAL_9]] to %[[VAL_2:.*]] : !fir.box>, !fir.ref>> -! CHECK: %[[VAL_10:.*]] = fir.load %[[VAL_2]] : !fir.ref>> +! CHECK-DAG: %[[X:.*]]:2 = hlfir.declare %[[VAL_0]] +! CHECK: %[[VAL_9:.*]] = fir.call @_QPreturn_pointer() +! CHECK: fir.save_result %[[VAL_9]] to %[[RESULT_ALLOCA:.*]] : !fir.box>, !fir.ref>> +! CHECK: %[[RESULT_DECL:.*]]:2 = hlfir.declare %[[RESULT_ALLOCA]] +! CHECK: %[[VAL_10:.*]] = fir.load %[[RESULT_DECL]]#0 : !fir.ref>> ! CHECK: %[[VAL_11:.*]] = fir.box_addr %[[VAL_10]] : (!fir.box>) -> !fir.ptr ! CHECK: %[[VAL_12:.*]] = fir.convert %[[VAL_11]] : (!fir.ptr) -> i64 ! CHECK: %[[VAL_13:.*]] = arith.constant 0 : i64 ! CHECK: %[[VAL_14:.*]] = arith.cmpi ne, %[[VAL_12]], %[[VAL_13]] : i64 +! CHECK: %[[VAL_8:.*]] = fir.load %[[X]]#0 : !fir.ref ! CHECK: %[[VAL_15:.*]] = fir.if %[[VAL_14]] -> (f32) { -! CHECK: %[[VAL_16:.*]] = fir.load %[[VAL_2]] : !fir.ref>> +! CHECK: %[[VAL_16:.*]] = fir.load %[[RESULT_DECL]]#0 : !fir.ref>> ! CHECK: %[[VAL_17:.*]] = fir.box_addr %[[VAL_16]] : (!fir.box>) -> !fir.ptr ! CHECK: %[[VAL_18:.*]] = fir.load %[[VAL_17]] : !fir.ptr ! CHECK: fir.result %[[VAL_18]] : f32 @@ -110,48 +115,35 @@ function return_pointer() ! CHECK: } ! CHECK: %[[VAL_20:.*]] = fir.undefined complex ! CHECK: %[[VAL_21:.*]] = fir.insert_value %[[VAL_20]], %[[VAL_8]], [0 : index] : (complex, f32) -> complex -! CHECK: fir.insert_value %[[VAL_21]], %[[VAL_23:.*]], [1 : index] : (complex, f32) -> complex +! CHECK: %[[VAL_22:.*]] = fir.insert_value %[[VAL_21]], %[[VAL_15]], [1 : index] : (complex, f32) -> complex end subroutine -! CHECK-LABEL: func @_QPcmplx_array( -! CHECK-SAME: %[[VAL_0:[^:]*]]: !fir.box> -! CHECK-SAME: %[[VAL_1:.*]]: !fir.box> +! CHECK-LABEL: func.func @_QPcmplx_array( +! CHECK-SAME: %[[VAL_0:.*]]: !fir.box> {fir.bindc_name = "x"}, %[[VAL_1:.*]]: !fir.box> {fir.bindc_name = "y", fir.optional}) subroutine cmplx_array(x, y) ! Important, note that the shape is taken from `x` and not `y` that ! may be absent. real :: x(:) real, optional :: y(:) print *, cmplx(x, y) -! CHECK: %[[VAL_7:.*]] = arith.constant 0 : index -! CHECK: %[[VAL_8:.*]]:3 = fir.box_dims %[[VAL_0]], %[[VAL_7]] : (!fir.box>, index) -> (index, index, index) -! CHECK: %[[VAL_9:.*]] = fir.array_load %[[VAL_0]] : (!fir.box>) -> !fir.array -! CHECK: %[[VAL_10:.*]] = fir.is_present %[[VAL_1]] : (!fir.box>) -> i1 -! CHECK: %[[VAL_11:.*]] = fir.zero_bits !fir.ref> -! CHECK: %[[VAL_12:.*]] = arith.constant 0 : index -! CHECK: %[[VAL_13:.*]] = fir.shape %[[VAL_12]] : (index) -> !fir.shape<1> -! CHECK: %[[VAL_14:.*]] = fir.embox %[[VAL_11]](%[[VAL_13]]) : (!fir.ref>, !fir.shape<1>) -> !fir.box> -! CHECK: %[[VAL_15:.*]] = arith.select %[[VAL_10]], %[[VAL_1]], %[[VAL_14]] : !fir.box> -! CHECK: %[[VAL_16:.*]] = fir.array_load %[[VAL_15]] {fir.optional} : (!fir.box>) -> !fir.array -! CHECK: %[[VAL_17:.*]] = fir.allocmem !fir.array>, %[[VAL_8]]#1 {uniq_name = ".array.expr"} -! CHECK: %[[VAL_18:.*]] = fir.shape %[[VAL_8]]#1 : (index) -> !fir.shape<1> -! CHECK: %[[VAL_19:.*]] = fir.array_load %[[VAL_17]](%[[VAL_18]]) : (!fir.heap>>, !fir.shape<1>) -> !fir.array> -! CHECK: %[[VAL_20:.*]] = arith.constant 1 : index -! CHECK: %[[VAL_21:.*]] = arith.constant 0 : index -! CHECK: %[[VAL_22:.*]] = arith.subi %[[VAL_8]]#1, %[[VAL_20]] : index -! CHECK: %[[VAL_23:.*]] = fir.do_loop %[[VAL_24:.*]] = %[[VAL_21]] to %[[VAL_22]] step %[[VAL_20]] unordered iter_args(%[[VAL_25:.*]] = %[[VAL_19]]) -> (!fir.array>) { - ! CHECK: %[[VAL_26:.*]] = fir.array_fetch %[[VAL_9]], %[[VAL_24]] : (!fir.array, index) -> f32 - ! CHECK: %[[VAL_27:.*]] = fir.if %[[VAL_10]] -> (f32) { - ! CHECK: %[[VAL_28:.*]] = fir.array_fetch %[[VAL_16]], %[[VAL_24]] : (!fir.array, index) -> f32 - ! CHECK: fir.result %[[VAL_28]] : f32 - ! CHECK: } else { - ! CHECK: %[[VAL_29:.*]] = arith.constant 0.000000e+00 : f32 - ! CHECK: fir.result %[[VAL_29]] : f32 - ! CHECK: } - ! CHECK: %[[VAL_30:.*]] = fir.undefined complex - ! CHECK: %[[VAL_31:.*]] = fir.insert_value %[[VAL_30]], %[[VAL_26]], [0 : index] : (complex, f32) -> complex - ! CHECK: %[[VAL_32:.*]] = fir.insert_value %[[VAL_31]], %[[VAL_33:.*]], [1 : index] : (complex, f32) -> complex - ! CHECK: %[[VAL_34:.*]] = fir.array_update %[[VAL_25]], %[[VAL_32]], %[[VAL_24]] : (!fir.array>, complex, index) -> !fir.array> - ! CHECK: fir.result %[[VAL_34]] : !fir.array> +! CHECK-DAG: %[[X:.*]]:2 = hlfir.declare %[[VAL_0]] +! CHECK-DAG: %[[Y:.*]]:2 = hlfir.declare %[[VAL_1]] +! CHECK: %[[IS_PRESENT:.*]] = fir.is_present %[[Y]]#0 : (!fir.box>) -> i1 +! CHECK: %[[ELEMENTAL:.*]] = hlfir.elemental %{{.*}} unordered : (!fir.shape<1>) -> !hlfir.expr> { +! CHECK: ^bb0(%[[VAL_24:.*]]: index): +! CHECK: %[[VAL_26_REF:.*]] = hlfir.designate %[[X]]#0 (%[[VAL_24]]) +! CHECK: %[[VAL_26:.*]] = fir.load %[[VAL_26_REF]] : !fir.ref +! CHECK: %[[VAL_27:.*]] = fir.if %[[IS_PRESENT]] -> (f32) { +! CHECK: %[[VAL_28_REF:.*]] = hlfir.designate %[[Y]]#0 (%[[VAL_24]]) +! CHECK: %[[VAL_28:.*]] = fir.load %[[VAL_28_REF]] : !fir.ref +! CHECK: fir.result %[[VAL_28]] : f32 +! CHECK: } else { +! CHECK: %[[VAL_29:.*]] = arith.constant 0.000000e+00 : f32 +! CHECK: fir.result %[[VAL_29]] : f32 +! CHECK: } +! CHECK: %[[VAL_30:.*]] = fir.undefined complex +! CHECK: %[[VAL_31:.*]] = fir.insert_value %[[VAL_30]], %[[VAL_26]], [0 : index] : (complex, f32) -> complex +! CHECK: %[[VAL_32:.*]] = fir.insert_value %[[VAL_31]], %[[VAL_27]], [1 : index] : (complex, f32) -> complex +! CHECK: hlfir.yield_element %[[VAL_32]] : complex ! CHECK: } -! CHECK: fir.array_merge_store end subroutine diff --git a/flang/test/Lower/Intrinsics/cpu_time.f90 b/flang/test/Lower/Intrinsics/cpu_time.f90 index 73eead3796444..1972074ff073f 100644 --- a/flang/test/Lower/Intrinsics/cpu_time.f90 +++ b/flang/test/Lower/Intrinsics/cpu_time.f90 @@ -1,10 +1,13 @@ -! RUN: bbc -emit-fir -hlfir=false %s -o - | FileCheck %s +! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s -! CHECK-LABEL: cpu_time_test +! CHECK-LABEL: func.func @_QPcpu_time_test( +! CHECK-SAME: %[[ARG0:.*]]: !fir.ref {fir.bindc_name = "t"}) subroutine cpu_time_test(t) real :: t - ! CHECK: %[[result64:[0-9]+]] = fir.call @_FortranACpuTime() {{.*}}: () -> f64 - ! CHECK: %[[result32:[0-9]+]] = fir.convert %[[result64]] : (f64) -> f32 - ! CHECK: fir.store %[[result32]] to %arg0 : !fir.ref + ! CHECK: %[[VAL_0:.*]] = fir.dummy_scope : !fir.dscope + ! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[ARG0]] dummy_scope %[[VAL_0]] arg 1 {uniq_name = "_QFcpu_time_testEt"} : (!fir.ref, !fir.dscope) -> (!fir.ref, !fir.ref) + ! CHECK: %[[result64:.*]] = fir.call @_FortranACpuTime() + ! CHECK: %[[result32:.*]] = fir.convert %[[result64]] : (f64) -> f32 + ! CHECK: fir.store %[[result32]] to %[[VAL_1]]#0 : !fir.ref call cpu_time(t) end subroutine