Skip to content

Commit 23991f3

Browse files
ceseomahesh-attarde
authored andcommitted
[Flang] Fix a crash when equivalence and namelist statements are used (llvm#150081)
Check for equivalence when generating namelist descriptors in IO.cpp. Fixes llvm#124489
1 parent bb9a56a commit 23991f3

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
@@ -468,8 +468,10 @@ getNamelistGroup(Fortran::lower::AbstractConverter &converter,
468468
fir::BoxType boxTy =
469469
fir::BoxType::get(fir::PointerType::get(converter.genType(s)));
470470
auto descFunc = [&](fir::FirOpBuilder &b) {
471+
bool couldBeInEquivalence =
472+
Fortran::semantics::FindEquivalenceSet(s) != nullptr;
471473
auto box = Fortran::lower::genInitialDataTarget(
472-
converter, loc, boxTy, *expr, /*couldBeInEquivalence=*/true);
474+
converter, loc, boxTy, *expr, couldBeInEquivalence);
473475
fir::HasValueOp::create(b, loc, box);
474476
};
475477
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)