Skip to content

Commit 3db29aa

Browse files
ceseotru
authored andcommitted
[Flang] Fix a crash when equivalence and namelist statements are used (#150081)
Check for equivalence when generating namelist descriptors in IO.cpp. Fixes #124489
1 parent 1db54c7 commit 3db29aa

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

flang/lib/Lower/IO.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,10 @@ getNamelistGroup(Fortran::lower::AbstractConverter &converter,
464464
fir::BoxType boxTy =
465465
fir::BoxType::get(fir::PointerType::get(converter.genType(s)));
466466
auto descFunc = [&](fir::FirOpBuilder &b) {
467+
bool couldBeInEquivalence =
468+
Fortran::semantics::FindEquivalenceSet(s) != nullptr;
467469
auto box = Fortran::lower::genInitialDataTarget(
468-
converter, loc, boxTy, *expr, /*couldBeInEquivalence=*/true);
470+
converter, loc, boxTy, *expr, couldBeInEquivalence);
469471
b.create<fir::HasValueOp>(loc, box);
470472
};
471473
builder.createGlobalConstant(loc, boxTy, mangleName, descFunc, linkOnce);

flang/test/Lower/equivalence-3.f

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
! RUN: bbc -emit-fir -o - %s | FileCheck %s
2+
3+
! CHECK-LABEL: func @_QQmain
4+
program main
5+
real a1,a2
6+
equivalence (a1,a2)
7+
! A fir.alloca should never appear in a global constant initialization.
8+
! CHECK: fir.global linkonce @_QFEx1.desc constant : !fir.box<!fir.ptr<!fir.array<5xf64>>>
9+
! CHECK: arith.constant 5 : index
10+
! CHECK:fir.address_of(@_QFEx1) : !fir.ref<!fir.array<5xf64>>
11+
! CHECK: fir.shape %c5 : (index) -> !fir.shape<1>
12+
! CHECK: fir.declare %0(%1) {uniq_name = "_QFEx1"} : (!fir.ref<!fir.array<5xf64>>, !fir.shape<1>) -> !fir.ref<!fir.array<5xf64>>
13+
! CHECK: fir.embox %2(%1) : (!fir.ref<!fir.array<5xf64>>, !fir.shape<1>) -> !fir.box<!fir.array<5xf64>>
14+
! CHECK: fir.rebox %3 : (!fir.box<!fir.array<5xf64>>) -> !fir.box<!fir.ptr<!fir.array<5xf64>>>
15+
! CHECK: fir.has_value %4 : !fir.box<!fir.ptr<!fir.array<5xf64>>>
16+
real*8 x1(5)
17+
namelist /y1/x1
18+
read (5,y1)
19+
end

0 commit comments

Comments
 (0)