Skip to content

[OpenMP] Fix infinite loop on recursive initializers #126269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions clang/lib/Sema/SemaOpenMP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22819,8 +22819,12 @@ class GlobalDeclRefChecker final : public StmtVisitor<GlobalDeclRefChecker> {
void declareTargetInitializer(Decl *TD) {
A = TD->getAttr<OMPDeclareTargetDeclAttr>();
DeclVector.push_back(cast<VarDecl>(TD));
llvm::SmallDenseSet<Decl *> Visited;
while (!DeclVector.empty()) {
VarDecl *TargetVarDecl = DeclVector.pop_back_val();
if (!Visited.insert(TargetVarDecl).second)
continue;

if (TargetVarDecl->hasAttr<OMPDeclareTargetDeclAttr>() &&
TargetVarDecl->hasInit() && TargetVarDecl->hasGlobalStorage()) {
if (Expr *Ex = TargetVarDecl->getInit())
Expand Down
5 changes: 5 additions & 0 deletions clang/test/OpenMP/declare_target_messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
// RUN: %clang_cc1 %{common_opts_mac} -verify=expected,omp51,ompvar,omp45-to-51,omp5-and-51,omp5-or-later,omp5-or-later-var,omp45-to-51-var,omp45-to-51-clause,host-5-and-51,no-host5-and-51 -fopenmp %{limit} -o - %s
// RUN: %clang_cc1 %{common_opts_mac} -verify=expected,omp52,ompvar,omp5-or-later,omp5-or-later-var %{openmp60} %{limit} -o - %s

#pragma omp begin declare target
static int gg;
// expected-warning@+1 {{variable 'recursive' is uninitialized when used within its own initialization}}
int recursive = recursive ^ 3 + gg;
#pragma omp end declare target

// expected-error@+1 {{unexpected OpenMP directive '#pragma omp end declare target'}}
#pragma omp end declare target
Expand Down