-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
Summary: If the user tried to initialize a gobal declare target variable with itself the compiler will hang forever. Add a visited set to make sure this stops. Fixes: llvm#69194
@llvm/pr-subscribers-clang Author: Joseph Huber (jhuber6) ChangesSummary: Fixes: #69194 Full diff: https://github.com/llvm/llvm-project/pull/126269.diff 2 Files Affected:
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index b060039d188a1bc..91e459c64030a0b 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -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::DenseSet<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())
diff --git a/clang/test/OpenMP/declare_target_messages.cpp b/clang/test/OpenMP/declare_target_messages.cpp
index ce5a833b3866a9b..3c0e766cf72ca8e 100644
--- a/clang/test/OpenMP/declare_target_messages.cpp
+++ b/clang/test/OpenMP/declare_target_messages.cpp
@@ -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
|
The fix looks reasonable to me. @alexey-bataev WDYT? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG with a nit
/cherry-pick 605a9e3 |
Failed to cherry-pick: 605a9e3 https://github.com/llvm/llvm-project/actions/runs/13206970400 Please manually backport the fix and push it to your github fork. Once this is done, please create a pull request |
Summary: If the user tried to initialize a gobal declare target variable with itself the compiler will hang forever. Add a visited set to make sure this stops. Fixes: llvm#69194
Summary:
If the user tried to initialize a gobal declare target variable with
itself the compiler will hang forever. Add a visited set to make sure
this stops.
Fixes: #69194