[flang-commits] [flang] [flang][hlfir] get rid of box when translating scalars to extented value (PR #125059)

via flang-commits flang-commits at lists.llvm.org
Thu Jan 30 05:43:19 PST 2025


https://github.com/jeanPerier created https://github.com/llvm/llvm-project/pull/125059

The code in `translateToExtendedValue(hlfir::Entity)` was not getting rid of the fir.box for scalars because isSimplyContiguous() returned false for them.

This created issues downstream because utilities using fir::ExtendedValue were not implemented to work with intrinsic scalars fir.box.

fir.box of intrinsic scalars are not very commonly used as hlfir::Entity but they are allowed and should work where accepted.

>From 145f103d303e6a415e9ee020d06a21f7c61f5493 Mon Sep 17 00:00:00 2001
From: Jean Perier <jperier at nvidia.com>
Date: Thu, 30 Jan 2025 05:25:35 -0800
Subject: [PATCH] [flang][hlfir] get rid of box when translating scalars to
 extented value

---
 flang/include/flang/Optimizer/Builder/HLFIRTools.h |  2 +-
 flang/test/HLFIR/assign-codegen.fir                | 10 ++++++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/flang/include/flang/Optimizer/Builder/HLFIRTools.h b/flang/include/flang/Optimizer/Builder/HLFIRTools.h
index 0684ad0f926ec9..d8785969bb7247 100644
--- a/flang/include/flang/Optimizer/Builder/HLFIRTools.h
+++ b/flang/include/flang/Optimizer/Builder/HLFIRTools.h
@@ -125,7 +125,7 @@ class Entity : public mlir::Value {
   bool isSimplyContiguous() const {
     // If this can be described without a fir.box in FIR, this must
     // be contiguous.
-    if (!hlfir::isBoxAddressOrValueType(getFirBase().getType()))
+    if (!hlfir::isBoxAddressOrValueType(getFirBase().getType()) || isScalar())
       return true;
     // Otherwise, if this entity has a visible declaration in FIR,
     // or is the dereference of an allocatable or contiguous pointer
diff --git a/flang/test/HLFIR/assign-codegen.fir b/flang/test/HLFIR/assign-codegen.fir
index 581d1ab0e7739c..5e48784284a8b4 100644
--- a/flang/test/HLFIR/assign-codegen.fir
+++ b/flang/test/HLFIR/assign-codegen.fir
@@ -427,3 +427,13 @@ func.func @test_upoly_expr_assignment(%arg0: !fir.class<!fir.array<?xnone>> {fir
 // CHECK:           }
 // CHECK:           return
 // CHECK:         }
+
+func.func @test_scalar_box(%arg0: f32, %arg1: !fir.box<!fir.ptr<f32>>) {
+  hlfir.assign %arg0 to %arg1 : f32, !fir.box<!fir.ptr<f32>>
+  return
+}
+// CHECK-LABEL:   func.func @test_scalar_box(
+// CHECK-SAME:                               %[[VAL_0:.*]]: f32,
+// CHECK-SAME:                               %[[VAL_1:.*]]: !fir.box<!fir.ptr<f32>>) {
+// CHECK:           %[[VAL_2:.*]] = fir.box_addr %[[VAL_1]] : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32>
+// CHECK:           fir.store %[[VAL_0]] to %[[VAL_2]] : !fir.ptr<f32>



More information about the flang-commits mailing list