[flang-commits] [flang] e77fc0d - [flang] Relax the check for polymorphic pointer in storage_size intrinsic

Valentin Clement via flang-commits flang-commits at lists.llvm.org
Thu Feb 23 08:30:31 PST 2023


Author: Valentin Clement
Date: 2023-02-23T17:30:21+01:00
New Revision: e77fc0dd76ab2aade6fed2358dbc603c0c80d20c

URL: https://github.com/llvm/llvm-project/commit/e77fc0dd76ab2aade6fed2358dbc603c0c80d20c
DIFF: https://github.com/llvm/llvm-project/commit/e77fc0dd76ab2aade6fed2358dbc603c0c80d20c.diff

LOG: [flang] Relax the check for polymorphic pointer in storage_size intrinsic

The runtime check was a too strong as the standard says.
> If it is polymorphic it shall not be an undefined pointer.
The check was checking if the pointer was associated.
Remove the check as other compilers do.

Depends on D144643

Reviewed By: PeteSteinfeld

Differential Revision: https://reviews.llvm.org/D144644

Added: 
    

Modified: 
    flang/lib/Optimizer/Builder/IntrinsicCall.cpp
    flang/test/Lower/Intrinsics/storage_size.f90

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
index 926aea53e20f..5148938eca79 100644
--- a/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
+++ b/flang/lib/Optimizer/Builder/IntrinsicCall.cpp
@@ -4899,9 +4899,6 @@ IntrinsicLibrary::genStorageSize(mlir::Type resultType,
         fir::isPointerType(boxTy)
             ? "unlimited polymorphic disassociated POINTER in STORAGE_SIZE"
             : "unlimited polymorphic unallocated ALLOCATABLE in STORAGE_SIZE";
-  } else if (fir::isPolymorphicType(boxTy) && fir::isPointerType(boxTy)) {
-    needRuntimeCheck = true;
-    errorMsg = "polymorphic disassociated POINTER in STORAGE_SIZE";
   }
   const fir::MutableBoxValue *mutBox = args[0].getBoxOf<fir::MutableBoxValue>();
   if (needRuntimeCheck && mutBox) {

diff  --git a/flang/test/Lower/Intrinsics/storage_size.f90 b/flang/test/Lower/Intrinsics/storage_size.f90
index 6cc883ebf4da..06bc8eec2e5d 100644
--- a/flang/test/Lower/Intrinsics/storage_size.f90
+++ b/flang/test/Lower/Intrinsics/storage_size.f90
@@ -72,14 +72,6 @@ integer function polymorphic_pointer(p) result(size)
 ! CHECK-SAME: %[[P:.*]]: !fir.ref<!fir.class<!fir.ptr<!fir.type<_QMstorage_size_testTp1{a:i32}>>>> {fir.bindc_name = "p"}) -> i32 {
 ! CHECK: %[[SIZE:.*]] = fir.alloca i32 {bindc_name = "size", uniq_name = "_QMstorage_size_testFpolymorphic_pointerEsize"}
 ! CHECK: %[[LOAD_P:.*]] = fir.load %[[P]] : !fir.ref<!fir.class<!fir.ptr<!fir.type<_QMstorage_size_testTp1{a:i32}>>>>
-! CHECK: %[[P_ADDR:.*]] = fir.box_addr %[[LOAD_P]] : (!fir.class<!fir.ptr<!fir.type<_QMstorage_size_testTp1{a:i32}>>>) -> !fir.ptr<!fir.type<_QMstorage_size_testTp1{a:i32}>>
-! CHECK: %[[P_ADDR_I64:.*]] = fir.convert %[[P_ADDR]] : (!fir.ptr<!fir.type<_QMstorage_size_testTp1{a:i32}>>) -> i64
-! CHECK: %[[C0:.*]] = arith.constant 0 : i64
-! CHECK: %[[IS_NULL_ADDR:.*]] = arith.cmpi eq, %[[P_ADDR_I64]], %[[C0]] : i64
-! CHECK: fir.if %[[IS_NULL_ADDR]] {
-! CHECK:   %{{.*}} = fir.call @_FortranAReportFatalUserError(%{{.*}}, %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref<i8>, !fir.ref<i8>, i32) -> none
-! CHECK: }
-! CHECK: %[[LOAD_P:.*]] = fir.load %[[P]] : !fir.ref<!fir.class<!fir.ptr<!fir.type<_QMstorage_size_testTp1{a:i32}>>>>
 ! CHECK: %[[ELE_SIZE:.*]] = fir.box_elesize %[[LOAD_P]] : (!fir.class<!fir.ptr<!fir.type<_QMstorage_size_testTp1{a:i32}>>>) -> i32
 ! CHECK: %[[C8:.*]] = arith.constant 8 : i32
 ! CHECK: %[[BITS:.*]] = arith.muli %[[ELE_SIZE]], %[[C8]] : i32


        


More information about the flang-commits mailing list