Skip to content

Commit 242aa8c

Browse files
authored
[flang][hlfir] get rid of box when translating scalars to extented value (#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.
1 parent 3cef99f commit 242aa8c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

flang/include/flang/Optimizer/Builder/HLFIRTools.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ class Entity : public mlir::Value {
125125
bool isSimplyContiguous() const {
126126
// If this can be described without a fir.box in FIR, this must
127127
// be contiguous.
128-
if (!hlfir::isBoxAddressOrValueType(getFirBase().getType()))
128+
if (!hlfir::isBoxAddressOrValueType(getFirBase().getType()) || isScalar())
129129
return true;
130130
// Otherwise, if this entity has a visible declaration in FIR,
131131
// or is the dereference of an allocatable or contiguous pointer

flang/test/HLFIR/assign-codegen.fir

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,3 +427,13 @@ func.func @test_upoly_expr_assignment(%arg0: !fir.class<!fir.array<?xnone>> {fir
427427
// CHECK: }
428428
// CHECK: return
429429
// CHECK: }
430+
431+
func.func @test_scalar_box(%arg0: f32, %arg1: !fir.box<!fir.ptr<f32>>) {
432+
hlfir.assign %arg0 to %arg1 : f32, !fir.box<!fir.ptr<f32>>
433+
return
434+
}
435+
// CHECK-LABEL: func.func @test_scalar_box(
436+
// CHECK-SAME: %[[VAL_0:.*]]: f32,
437+
// CHECK-SAME: %[[VAL_1:.*]]: !fir.box<!fir.ptr<f32>>) {
438+
// CHECK: %[[VAL_2:.*]] = fir.box_addr %[[VAL_1]] : (!fir.box<!fir.ptr<f32>>) -> !fir.ptr<f32>
439+
// CHECK: fir.store %[[VAL_0]] to %[[VAL_2]] : !fir.ptr<f32>

0 commit comments

Comments
 (0)