[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
Tue Apr 25 00:03:10 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG90cf1014243b: [flang][hlfir] Lower NULL(MOLD) to a variable (authored by jeanPerier).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149053/new/

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.516642.patch
Type: text/x-patch
Size: 2352 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230425/1dc7c5f0/attachment-0001.bin>


More information about the flang-commits mailing list