Skip to content

Commit 90da688

Browse files
authored
[flang][openacc] Avoid creation of duplicate global ctor (#71846)
PR #70698 relax the duplication rule in acc declare clauses. This lead to potential duplicate creation of the global constructor/destructor. This patch make sure to not generate a duplicate ctor/dtor.
1 parent 0be4c6b commit 90da688

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

flang/lib/Lower/OpenACC.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2906,6 +2906,11 @@ static void genGlobalCtors(Fortran::lower::AbstractConverter &converter,
29062906
std::stringstream asFortran;
29072907
asFortran << name->symbol->name().ToString();
29082908

2909+
if (builder.getModule()
2910+
.lookupSymbol<mlir::acc::GlobalConstructorOp>(
2911+
declareGlobalCtorName.str()))
2912+
return;
2913+
29092914
if (!globalOp) {
29102915
if (Fortran::semantics::FindEquivalenceSet(*name->symbol)) {
29112916
for (Fortran::semantics::EquivalenceObject eqObj :

flang/test/Lower/OpenACC/HLFIR/acc-declare.f90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,3 +304,12 @@ module acc_declare_equivalent2
304304
! ALL: acc.delete accPtr(%[[DEVICEPTR]] : !fir.ref<!fir.array<40xi8>>) {dataClause = #acc<data_clause acc_create>, name = "v2", structured = false}
305305
! ALL: acc.terminator
306306
! ALL: }
307+
308+
module acc_declare_allocatable_test2
309+
integer, allocatable :: data1(:)
310+
integer, allocatable :: data2(:)
311+
!$acc declare create(data1, data2, data1)
312+
end module
313+
314+
! ALL-LABEL: acc.global_ctor @_QMacc_declare_allocatable_test2Edata1_acc_ctor
315+
! ALL-LABEL: acc.global_ctor @_QMacc_declare_allocatable_test2Edata2_acc_ctor

0 commit comments

Comments
 (0)