// RUN: fir-opt --fir-add-alias-tags --split-input-file %s | FileCheck %s // This test demonstrates the need for fir.dummy_scope even // when a function does not have dummy arguments. // // The original source is: // module m // integer :: glob // end module m // subroutine test1 // use m // call inner(glob) // glob = 2 // contains // subroutine inner(x) // integer :: x // integer :: y // y = 1 // x = y // end subroutine inner // end subroutine test1 // // 'inner' function is manually inlined in FIR. // When fir.dummy_scope is missing, TBAA tags for glob and x // are placed into the same TBAA root. Since glob is a global // and x is a dummy argument, TBAA ends up reporting no-alias // for them, which is incorrect. module attributes {dlti.dl_spec = #dlti.dl_spec : vector<4xi64>, i1 = dense<8> : vector<2xi64>, i8 = dense<8> : vector<2xi64>, i16 = dense<16> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, i64 = dense<[32, 64]> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, "dlti.endianness" = "little">, llvm.data_layout = ""} { func.func @_QPtest1() attributes {noinline} { %c1_i32 = arith.constant 1 : i32 %c2_i32 = arith.constant 2 : i32 %0 = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFtest1FinnerEy"} %1 = fir.address_of(@_QMmEglob) : !fir.ref %2 = fir.declare %1 {uniq_name = "_QMmEglob"} : (!fir.ref) -> !fir.ref %3 = fir.dummy_scope : !fir.dscope %4 = fir.declare %2 dummy_scope %3 {uniq_name = "_QFtest1FinnerEx"} : (!fir.ref, !fir.dscope) -> !fir.ref %5 = fir.declare %0 {uniq_name = "_QFtest1FinnerEy"} : (!fir.ref) -> !fir.ref fir.store %c1_i32 to %5 : !fir.ref %6 = fir.load %5 : !fir.ref fir.store %6 to %4 : !fir.ref fir.store %c2_i32 to %2 : !fir.ref return } fir.global @_QMmEglob : i32 } // CHECK: #[[$ATTR_0:.+]] = #llvm.tbaa_root // CHECK: #[[$ATTR_1:.+]] = #llvm.tbaa_type_desc}> // CHECK: #[[$ANYDATA:.+]] = #llvm.tbaa_type_desc}> // CHECK: #[[$LOCAL_ATTR_0:.+]] = #llvm.tbaa_type_desc}> // CHECK: #[[$ATTR_3:.+]] = #llvm.tbaa_type_desc}> // CHECK: #[[$ATTR_4:.+]] = #llvm.tbaa_type_desc}> // CHECK: #[[$LOCAL_ATTR_1:.+]] = #llvm.tbaa_type_desc}> // CHECK: #[[$ATTR_5:.+]] = #llvm.tbaa_type_desc}> // CHECK: #[[$ATTR_6:.+]] = #llvm.tbaa_type_desc}> // CHECK: #[[$LOCAL_ATTR_2:.+]] = #llvm.tbaa_tag // CHECK: #[[$ATTR_7:.+]] = #llvm.tbaa_tag // CHECK: #[[$ATTR_8:.+]] = #llvm.tbaa_tag // CHECK-LABEL: func.func @_QPtest1() attributes {noinline} { // CHECK: %[[VAL_2:.*]] = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFtest1FinnerEy"} // CHECK: %[[VAL_3:.*]] = fir.address_of(@_QMmEglob) : !fir.ref // CHECK: %[[VAL_4:.*]] = fir.declare %[[VAL_3]] {uniq_name = "_QMmEglob"} : (!fir.ref) -> !fir.ref // CHECK: %[[VAL_5:.*]] = fir.dummy_scope : !fir.dscope // CHECK: %[[VAL_6:.*]] = fir.declare %[[VAL_4]] dummy_scope %[[VAL_5]] {uniq_name = "_QFtest1FinnerEx"} : (!fir.ref, !fir.dscope) -> !fir.ref // CHECK: %[[VAL_7:.*]] = fir.declare %[[VAL_2]] {uniq_name = "_QFtest1FinnerEy"} : (!fir.ref) -> !fir.ref // CHECK: fir.store %{{.*}} to %[[VAL_7]] {tbaa = [#[[$LOCAL_ATTR_2]]]} : !fir.ref // CHECK: %[[VAL_8:.*]] = fir.load %[[VAL_7]] {tbaa = [#[[$LOCAL_ATTR_2]]]} : !fir.ref // CHECK: fir.store %[[VAL_8]] to %[[VAL_6]] {tbaa = [#[[$ATTR_7]]]} : !fir.ref // CHECK: fir.store %{{.*}} to %[[VAL_4]] {tbaa = [#[[$ATTR_8]]]} : !fir.ref // ----- // This test has fir.dummy_scope in place, and TBAA is correct. module attributes {dlti.dl_spec = #dlti.dl_spec : vector<4xi64>, i1 = dense<8> : vector<2xi64>, i8 = dense<8> : vector<2xi64>, i16 = dense<16> : vector<2xi64>, i32 = dense<32> : vector<2xi64>, i64 = dense<[32, 64]> : vector<2xi64>, f16 = dense<16> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, f128 = dense<128> : vector<2xi64>, "dlti.endianness" = "little">, llvm.data_layout = ""} { func.func @_QPtest2() attributes {noinline} { %c1_i32 = arith.constant 1 : i32 %c2_i32 = arith.constant 2 : i32 %0 = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFtest2FinnerEy"} %test_dummy_scope = fir.dummy_scope : !fir.dscope %1 = fir.address_of(@_QMmEglob) : !fir.ref %2 = fir.declare %1 {uniq_name = "_QMmEglob"} : (!fir.ref) -> !fir.ref %3 = fir.dummy_scope : !fir.dscope %4 = fir.declare %2 dummy_scope %3 {uniq_name = "_QFtest2FinnerEx"} : (!fir.ref, !fir.dscope) -> !fir.ref %5 = fir.declare %0 {uniq_name = "_QFtest2FinnerEy"} : (!fir.ref) -> !fir.ref fir.store %c1_i32 to %5 : !fir.ref %6 = fir.load %5 : !fir.ref fir.store %6 to %4 : !fir.ref fir.store %c2_i32 to %2 : !fir.ref return } fir.global @_QMmEglob : i32 } // CHECK: #[[$ATTR_0:.+]] = #llvm.tbaa_root // CHECK: #[[$ATTR_1:.+]] = #llvm.tbaa_root // CHECK: #[[$ATTR_2:.+]] = #llvm.tbaa_type_desc}> // CHECK: #[[$ATTR_3:.+]] = #llvm.tbaa_type_desc}> // CHECK: #[[$ATTR_4:.+]] = #llvm.tbaa_type_desc}> // CHECK: #[[$ATTR_5:.+]] = #llvm.tbaa_type_desc}> // CHECK: #[[$ATTR_6:.+]] = #llvm.tbaa_type_desc}> // CHECK: #[[$ATTR_7:.+]] = #llvm.tbaa_type_desc}> // CHECK: #[[$ATTR_8:.+]] = #llvm.tbaa_type_desc}> // CHECK: #[[$ATTR_9:.+]] = #llvm.tbaa_type_desc}> // CHECK: #[[$ATTR_10:.+]] = #llvm.tbaa_type_desc}> // CHECK: #[[$ATTR_11:.+]] = #llvm.tbaa_type_desc}> // CHECK: #[[$ATTR_12:.+]] = #llvm.tbaa_tag // CHECK: #[[$ATTR_13:.+]] = #llvm.tbaa_tag // CHECK: #[[$ATTR_14:.+]] = #llvm.tbaa_tag // CHECK-LABEL: func.func @_QPtest2() attributes {noinline} { // CHECK: %[[CONSTANT_0:.*]] = arith.constant 1 : i32 // CHECK: %[[CONSTANT_1:.*]] = arith.constant 2 : i32 // CHECK: %[[ALLOCA_0:.*]] = fir.alloca i32 {bindc_name = "y", uniq_name = "_QFtest2FinnerEy"} // CHECK: %[[DUMMY_SCOPE_0:.*]] = fir.dummy_scope : !fir.dscope // CHECK: %[[ADDRESS_OF_0:.*]] = fir.address_of(@_QMmEglob) : !fir.ref // CHECK: %[[DECLARE_0:.*]] = fir.declare %[[ADDRESS_OF_0]] {uniq_name = "_QMmEglob"} : (!fir.ref) -> !fir.ref // CHECK: %[[DUMMY_SCOPE_1:.*]] = fir.dummy_scope : !fir.dscope // CHECK: %[[DECLARE_1:.*]] = fir.declare %[[DECLARE_0]] dummy_scope %[[DUMMY_SCOPE_1]] {uniq_name = "_QFtest2FinnerEx"} : (!fir.ref, !fir.dscope) -> !fir.ref // CHECK: %[[DECLARE_2:.*]] = fir.declare %[[ALLOCA_0]] {uniq_name = "_QFtest2FinnerEy"} : (!fir.ref) -> !fir.ref // CHECK: fir.store %[[CONSTANT_0]] to %[[DECLARE_2]] {tbaa = [#[[$ATTR_12]]]} : !fir.ref // CHECK: %[[LOAD_0:.*]] = fir.load %[[DECLARE_2]] {tbaa = [#[[$ATTR_12]]]} : !fir.ref // CHECK: fir.store %[[LOAD_0]] to %[[DECLARE_1]] {tbaa = [#[[$ATTR_13]]]} : !fir.ref // CHECK: fir.store %[[CONSTANT_1]] to %[[DECLARE_0]] {tbaa = [#[[$ATTR_14]]]} : !fir.ref