1 ! RUN: bbc -emit-hlfir %s -o - | FileCheck %s
2 ! RUN: %flang_fc1 -emit-hlfir %s -o - | FileCheck %s
4 ! CHECK-LABEL: func.func @_QPmalloc_ptr() {
5 subroutine malloc_ptr()
8 ! CHECK: %[[X:.*]] = fir.alloca !fir.box<!fir.ptr<i32>>
9 ! CHECK: %[[X_PTR:.*]] = fir.alloca i64 {bindc_name = "ptr_x", uniq_name = "_QFmalloc_ptrEptr_x"}
10 ! CHECK: %[[X_PTR_DECL:.*]]:2 = hlfir.declare %[[X_PTR]] {uniq_name = "_QFmalloc_ptrEptr_x"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
11 ! CHECK: %[[CST:.*]] = arith.constant 4 : i32
12 ! CHECK: %[[CST_I64:.*]] = fir.convert %[[CST]] : (i32) -> i64
13 ! CHECK: %[[ALLOC:.*]] = fir.call @_FortranAMalloc(%[[CST_I64]]) fastmath<contract> : (i64) -> i64
14 ! CHECK: hlfir.assign %[[ALLOC]] to %[[X_PTR_DECL]]#0 : i64, !fir.ref<i64>
19 ! gfortran allows malloc to be assigned to integers, so we accept it.
21 ! CHECK-LABEL: func.func @_QPmalloc_i8() {
22 subroutine malloc_i8()
24 ! CHECK: %[[X:.*]] = fir.alloca i8 {bindc_name = "x", uniq_name = "_QFmalloc_i8Ex"}
25 ! CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X]] {uniq_name = "_QFmalloc_i8Ex"} : (!fir.ref<i8>) -> (!fir.ref<i8>, !fir.ref<i8>)
26 ! CHECK: %[[CST:.*]] = arith.constant 1 : i32
27 ! CHECK: %[[CST_I64:.*]] = fir.convert %[[CST]] : (i32) -> i64
28 ! CHECK: %[[ALLOC:.*]] = fir.call @_FortranAMalloc(%[[CST_I64]]) fastmath<contract> : (i64) -> i64
29 ! CHECK: %[[ALLOC_I8:.*]] = fir.convert %[[ALLOC]] : (i64) -> i8
30 ! CHECK: hlfir.assign %[[ALLOC_I8]] to %[[X_DECL]]#0 : i8, !fir.ref<i8>
35 ! CHECK-LABEL: func.func @_QPmalloc_i16() {
36 subroutine malloc_i16()
38 ! CHECK: %[[X:.*]] = fir.alloca i16 {bindc_name = "x", uniq_name = "_QFmalloc_i16Ex"}
39 ! CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X]] {uniq_name = "_QFmalloc_i16Ex"} : (!fir.ref<i16>) -> (!fir.ref<i16>, !fir.ref<i16>)
40 ! CHECK: %[[CST:.*]] = arith.constant 1 : i32
41 ! CHECK: %[[CST_I64:.*]] = fir.convert %[[CST]] : (i32) -> i64
42 ! CHECK: %[[ALLOC:.*]] = fir.call @_FortranAMalloc(%[[CST_I64]]) fastmath<contract> : (i64) -> i64
43 ! CHECK: %[[ALLOC_I16:.*]] = fir.convert %[[ALLOC]] : (i64) -> i16
44 ! CHECK: hlfir.assign %[[ALLOC_I16]] to %[[X_DECL]]#0 : i16, !fir.ref<i16>
50 ! CHECK-LABEL: func.func @_QPmalloc_i32() {
51 subroutine malloc_i32()
53 ! CHECK: %[[X:.*]] = fir.alloca i32 {bindc_name = "x", uniq_name = "_QFmalloc_i32Ex"}
54 ! CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X]] {uniq_name = "_QFmalloc_i32Ex"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
55 ! CHECK: %[[CST:.*]] = arith.constant 1 : i32
56 ! CHECK: %[[CST_I64:.*]] = fir.convert %[[CST]] : (i32) -> i64
57 ! CHECK: %[[ALLOC:.*]] = fir.call @_FortranAMalloc(%[[CST_I64]]) fastmath<contract> : (i64) -> i64
58 ! CHECK: %[[ALLOC_I32:.*]] = fir.convert %[[ALLOC]] : (i64) -> i32
59 ! CHECK: hlfir.assign %[[ALLOC_I32]] to %[[X_DECL]]#0 : i32, !fir.ref<i32>
64 ! CHECK-LABEL: func.func @_QPmalloc_i64() {
65 subroutine malloc_i64()
67 ! CHECK: %[[X:.*]] = fir.alloca i64 {bindc_name = "x", uniq_name = "_QFmalloc_i64Ex"}
68 ! CHECK: %[[X_DECL:.*]]:2 = hlfir.declare %[[X]] {uniq_name = "_QFmalloc_i64Ex"} : (!fir.ref<i64>) -> (!fir.ref<i64>, !fir.ref<i64>)
69 ! CHECK: %[[CST:.*]] = arith.constant 1 : i32
70 ! CHECK: %[[CST_I64:.*]] = fir.convert %[[CST]] : (i32) -> i64
71 ! CHECK: %[[ALLOC:.*]] = fir.call @_FortranAMalloc(%[[CST_I64]]) fastmath<contract> : (i64) -> i64
72 ! CHECK: hlfir.assign %[[ALLOC]] to %[[X_DECL]]#0 : i64, !fir.ref<i64>