[flang-commits] [PATCH] D149053: [flang][hlfir] Lower NULL(MOLD) to a variable
Jean Perier via Phabricator via flang-commits
flang-commits at lists.llvm.org
Mon Apr 24 04:33:12 PDT 2023
jeanPerier created this revision.
jeanPerier added reviewers: vzakhari, clementval.
jeanPerier added a project: Flang.
Herald added subscribers: sunshaoce, mehdi_amini, jdoerfert.
Herald added a project: All.
jeanPerier requested review of this revision.
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).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D149053
Files:
flang/lib/Lower/ConvertCall.cpp
flang/test/Lower/HLFIR/null.f90
Index: flang/test/Lower/HLFIR/null.f90
===================================================================
--- /dev/null
+++ 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>>>>) -> ()
Index: flang/lib/Lower/ConvertCall.cpp
===================================================================
--- flang/lib/Lower/ConvertCall.cpp
+++ flang/lib/Lower/ConvertCall.cpp
@@ -1247,8 +1247,10 @@
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149053.516349.patch
Type: text/x-patch
Size: 2352 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230424/24510046/attachment-0001.bin>
More information about the flang-commits
mailing list