[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.
This commit is contained in:
Valentin Clement (バレンタイン クレメン)
2023-11-09 12:57:30 -08:00
committed by GitHub
parent 0be4c6b948
commit 90da688bac
2 changed files with 14 additions and 0 deletions

View File

@@ -2906,6 +2906,11 @@ static void genGlobalCtors(Fortran::lower::AbstractConverter &converter,
std::stringstream asFortran;
asFortran << name->symbol->name().ToString();
if (builder.getModule()
.lookupSymbol<mlir::acc::GlobalConstructorOp>(
declareGlobalCtorName.str()))
return;
if (!globalOp) {
if (Fortran::semantics::FindEquivalenceSet(*name->symbol)) {
for (Fortran::semantics::EquivalenceObject eqObj :

View File

@@ -304,3 +304,12 @@ end module
! ALL: acc.delete accPtr(%[[DEVICEPTR]] : !fir.ref<!fir.array<40xi8>>) {dataClause = #acc<data_clause acc_create>, name = "v2", structured = false}
! ALL: acc.terminator
! ALL: }
module acc_declare_allocatable_test2
integer, allocatable :: data1(:)
integer, allocatable :: data2(:)
!$acc declare create(data1, data2, data1)
end module
! ALL-LABEL: acc.global_ctor @_QMacc_declare_allocatable_test2Edata1_acc_ctor
! ALL-LABEL: acc.global_ctor @_QMacc_declare_allocatable_test2Edata2_acc_ctor