123 lines · plain
1// RUN: fir-opt %s --split-input-file --pass-pipeline="builtin.module(func.func(test-acc-pointer-like-interface{test-mode=alloc}))" 2>&1 | FileCheck %s2 3// The tests here use a synthetic hlfir.declare in order to ensure that the hlfir dialect is4// loaded. This is required because the pass used is part of OpenACC test passes outside of5// flang and the APIs being test may generate hlfir even when it does not appear.6 7func.func @test_ref_scalar_alloc() {8 %0 = fir.alloca f32 {test.ptr}9 %1:2 = hlfir.declare %0 {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)10 // CHECK: Successfully generated alloc for operation: %{{.*}} = fir.alloca f32 {test.ptr}11 // CHECK: Generated: %{{.*}} = fir.alloca f3212 return13}14 15// -----16 17func.func @test_ref_static_array_alloc() {18 %0 = fir.alloca !fir.array<10x20xf32> {test.ptr}19 %var = fir.alloca f3220 %1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)21 // CHECK: Successfully generated alloc for operation: %{{.*}} = fir.alloca !fir.array<10x20xf32> {test.ptr}22 // CHECK: Generated: %{{.*}} = fir.alloca !fir.array<10x20xf32>23 return24}25 26// -----27 28func.func @test_ref_derived_type_alloc() {29 %0 = fir.alloca !fir.type<_QTt{i:i32}> {test.ptr}30 %var = fir.alloca f3231 %1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)32 // CHECK: Successfully generated alloc for operation: %{{.*}} = fir.alloca !fir.type<_QTt{i:i32}> {test.ptr}33 // CHECK: Generated: %{{.*}} = fir.alloca !fir.type<_QTt{i:i32}>34 return35}36 37// -----38 39func.func @test_heap_scalar_alloc() {40 %0 = fir.allocmem f32 {test.ptr}41 %var = fir.alloca f3242 %1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)43 // CHECK: Successfully generated alloc for operation: %{{.*}} = fir.allocmem f32 {test.ptr}44 // CHECK: Generated: %{{.*}} = fir.allocmem f3245 return46}47 48// -----49 50func.func @test_heap_static_array_alloc() {51 %0 = fir.allocmem !fir.array<10x20xf32> {test.ptr}52 %var = fir.alloca f3253 %1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)54 // CHECK: Successfully generated alloc for operation: %{{.*}} = fir.allocmem !fir.array<10x20xf32> {test.ptr}55 // CHECK: Generated: %{{.*}} = fir.allocmem !fir.array<10x20xf32>56 return57}58 59// -----60 61func.func @test_ptr_scalar_alloc() {62 %0 = fir.alloca f3263 %1 = fir.convert %0 {test.ptr} : (!fir.ref<f32>) -> !fir.ptr<f32>64 %2:2 = hlfir.declare %0 {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)65 // CHECK: Successfully generated alloc for operation66 // CHECK: Generated: %{{.*}} = fir.alloca f3267 // CHECK: Generated: %{{.*}} = fir.convert %{{.*}} : (!fir.ref<f32>) -> !fir.ptr<f32>68 return69}70 71// -----72 73func.func @test_llvm_ptr_scalar_alloc() {74 %0 = fir.alloca f3275 %1 = fir.convert %0 {test.ptr} : (!fir.ref<f32>) -> !fir.llvm_ptr<f32>76 %2:2 = hlfir.declare %0 {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)77 // CHECK: Successfully generated alloc for operation78 // CHECK: Generated: %{{.*}} = fir.alloca f3279 // CHECK: Generated: %{{.*}} = fir.convert %{{.*}} : (!fir.ref<f32>) -> !fir.llvm_ptr<f32>80 return81}82 83// -----84 85func.func @test_dynamic_array_alloc_fails(%arg0: !fir.ref<!fir.array<?xf32>>) {86 %0 = fir.convert %arg0 {test.ptr} : (!fir.ref<!fir.array<?xf32>>) -> !fir.llvm_ptr<!fir.array<?xf32>>87 %var = fir.alloca f3288 %1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)89 // CHECK: Failed to generate alloc for operation: %{{.*}} = fir.convert %{{.*}} {test.ptr} : (!fir.ref<!fir.array<?xf32>>) -> !fir.llvm_ptr<!fir.array<?xf32>>90 return91}92 93// -----94 95func.func @test_unlimited_polymorphic_alloc_fails() {96 %0 = fir.alloca !fir.class<none> {test.ptr}97 %var = fir.alloca f3298 %1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)99 // CHECK: Failed to generate alloc for operation: %{{.*}} = fir.alloca !fir.class<none> {test.ptr}100 return101}102 103// -----104 105func.func @test_dynamic_char_alloc_fails(%arg0: !fir.ref<!fir.char<1,?>>) {106 %0 = fir.convert %arg0 {test.ptr} : (!fir.ref<!fir.char<1,?>>) -> !fir.llvm_ptr<!fir.char<1,?>>107 %var = fir.alloca f32108 %1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)109 // CHECK: Failed to generate alloc for operation: %{{.*}} = fir.convert %{{.*}} {test.ptr} : (!fir.ref<!fir.char<1,?>>) -> !fir.llvm_ptr<!fir.char<1,?>>110 return111}112 113// -----114 115func.func @test_static_char_alloc() {116 %0 = fir.alloca !fir.char<1,10> {test.ptr}117 %var = fir.alloca f32118 %1:2 = hlfir.declare %var {uniq_name = "load_hlfir"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)119 // CHECK: Successfully generated alloc for operation: %{{.*}} = fir.alloca !fir.char<1,10> {test.ptr}120 // CHECK: Generated: %{{.*}} = fir.alloca !fir.char<1,10>121 return122}123