From 90da688baccbedc448a79144b475db7ec482efdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Clement=20=28=E3=83=90=E3=83=AC=E3=83=B3?= =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=B3=20=E3=82=AF=E3=83=AC=E3=83=A1?= =?UTF-8?q?=E3=83=B3=29?= Date: Thu, 9 Nov 2023 12:57:30 -0800 Subject: [PATCH] [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. --- flang/lib/Lower/OpenACC.cpp | 5 +++++ flang/test/Lower/OpenACC/HLFIR/acc-declare.f90 | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp index 1c045b4273e2..f13fb41d2baf 100644 --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -2906,6 +2906,11 @@ static void genGlobalCtors(Fortran::lower::AbstractConverter &converter, std::stringstream asFortran; asFortran << name->symbol->name().ToString(); + if (builder.getModule() + .lookupSymbol( + declareGlobalCtorName.str())) + return; + if (!globalOp) { if (Fortran::semantics::FindEquivalenceSet(*name->symbol)) { for (Fortran::semantics::EquivalenceObject eqObj : diff --git a/flang/test/Lower/OpenACC/HLFIR/acc-declare.f90 b/flang/test/Lower/OpenACC/HLFIR/acc-declare.f90 index 6ebdd39802fe..7670cd654bf6 100644 --- a/flang/test/Lower/OpenACC/HLFIR/acc-declare.f90 +++ b/flang/test/Lower/OpenACC/HLFIR/acc-declare.f90 @@ -304,3 +304,12 @@ end module ! ALL: acc.delete accPtr(%[[DEVICEPTR]] : !fir.ref>) {dataClause = #acc, 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