diff options
| author | Jean Perier <jperier@nvidia.com> | 2023-04-25 09:02:18 +0200 |
|---|---|---|
| committer | Jean Perier <jperier@nvidia.com> | 2023-04-25 09:02:33 +0200 |
| commit | 90cf1014243b2edec249cab7a0bfde1e8c0fdf1c (patch) | |
| tree | 55cdce7360894f09f7feab45a9dadf1e980890f1 | |
| parent | c9e403d1992b064e9cd5b94749fb3f00fa0c0910 (diff) | |
| download | llvm-90cf1014243b2edec249cab7a0bfde1e8c0fdf1c.tar.gz llvm-90cf1014243b2edec249cab7a0bfde1e8c0fdf1c.tar.bz2 llvm-90cf1014243b2edec249cab7a0bfde1e8c0fdf1c.zip | |
[flang][hlfir] Lower NULL(MOLD) to a variable
HLFIR lowering promotes intrinsic results lowered in memory to
hlfir.expr to underline their read-only aspect once they are created.
NULL(MOLD) should not be promoted to an hlfir.expr, it is the NULL
variable (we need to see it as an address).
Reviewed By: clementval
Differential Revision: https://reviews.llvm.org/D149053
| -rw-r--r-- | flang/lib/Lower/ConvertCall.cpp | 6 | ||||
| -rw-r--r-- | flang/test/Lower/HLFIR/null.f90 | 20 |
2 files changed, 24 insertions, 2 deletions
diff --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp index 39a8be38cb29..8f1980362c4f 100644 --- a/flang/lib/Lower/ConvertCall.cpp +++ b/flang/lib/Lower/ConvertCall.cpp @@ -1247,8 +1247,10 @@ genIntrinsicRefCore(PreparedActualArguments &loweredActuals, hlfir::EntityWithAttributes resultEntity = extendedValueToHlfirEntity( loc, builder, resultExv, ".tmp.intrinsic_result"); // Move result into memory into an hlfir.expr since they are immutable from - // that point, and the result storage is some temp. - if (resultEntity.isVariable()) { + // that point, and the result storage is some temp. "Null" is special: it + // returns a null pointer variable that should not be transformed into a value + // (what matters is the memory address). + if (resultEntity.isVariable() && intrinsicName != "null") { hlfir::AsExprOp asExpr; // Character/Derived MERGE lowering returns one of its argument address // (this is the only intrinsic implemented in that way so far). The diff --git a/flang/test/Lower/HLFIR/null.f90 b/flang/test/Lower/HLFIR/null.f90 new file mode 100644 index 000000000000..6ae44082f316 --- /dev/null +++ b/flang/test/Lower/HLFIR/null.f90 @@ -0,0 +1,20 @@ +! Test lowering of NULL(MOLD) to HLFIR. +! RUN: bbc -emit-fir -hlfir -o - %s | FileCheck %s +subroutine test(mold) + integer, pointer :: mold(:) + interface + subroutine takes_ptr(p) + integer, pointer :: p(:) + end subroutine + end interface + call takes_ptr(null(mold)) +end subroutine +! CHECK-LABEL: func.func @_QPtest( +! CHECK: %[[VAL_1:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?xi32>>> +! CHECK: %[[VAL_3:.*]] = fir.zero_bits !fir.ptr<!fir.array<?xi32>> +! CHECK: %[[VAL_4:.*]] = arith.constant 0 : index +! CHECK: %[[VAL_5:.*]] = fir.shape %[[VAL_4]] : (index) -> !fir.shape<1> +! CHECK: %[[VAL_6:.*]] = fir.embox %[[VAL_3]](%[[VAL_5]]) : (!fir.ptr<!fir.array<?xi32>>, !fir.shape<1>) -> !fir.box<!fir.ptr<!fir.array<?xi32>>> +! CHECK: fir.store %[[VAL_6]] to %[[VAL_1]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>> +! CHECK: %[[VAL_7:.*]]:2 = hlfir.declare %[[VAL_1]] {uniq_name = ".tmp.intrinsic_result"} : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>>) -> (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>>, !fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>>) +! CHECK: fir.call @_QPtakes_ptr(%[[VAL_7]]#0) fastmath<contract> : (!fir.ref<!fir.box<!fir.ptr<!fir.array<?xi32>>>>) -> () |
