[clang] [clang][parse] Fix assertion in template instantiation after invalid atomic statement (PR #245556)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 24 01:40:46 PST 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Mahmoud Ahmed (anondeveg)
<details>
<summary>Changes</summary>
when using ```
#pragma acc atomic```
---
Full diff: https://github.com/llvm/llvm-project/pull/245556.diff
2 Files Affected:
- (modified) clang/lib/Parse/ParseOpenACC.cpp (+4-1)
- (modified) clang/test/SemaOpenACC/atomic-construct.cpp (+26)
``````````diff
diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp
index 692d00d60e91c0..25c1b7294080dd 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -620,6 +620,10 @@ unsigned getOpenACCScopeFlags(OpenACCDirectiveKind DirKind) {
Scope::OpenACCLoopConstructScope;
case OpenACCDirectiveKind::Loop:
return Scope::DeclScope | Scope::OpenACCLoopConstructScope;
+ case OpenACCDirectiveKind::Atomic:
+ // the associated statement gets its own scope, so a declaration in it
+ // (which is always invalid) cannot be referenced after the construct.
+ return Scope::DeclScope;
case OpenACCDirectiveKind::Data:
case OpenACCDirectiveKind::EnterData:
case OpenACCDirectiveKind::ExitData:
@@ -628,7 +632,6 @@ unsigned getOpenACCScopeFlags(OpenACCDirectiveKind DirKind) {
case OpenACCDirectiveKind::Init:
case OpenACCDirectiveKind::Shutdown:
case OpenACCDirectiveKind::Cache:
- case OpenACCDirectiveKind::Atomic:
case OpenACCDirectiveKind::Declare:
case OpenACCDirectiveKind::Routine:
case OpenACCDirectiveKind::Set:
diff --git a/clang/test/SemaOpenACC/atomic-construct.cpp b/clang/test/SemaOpenACC/atomic-construct.cpp
index 056154e5dad3df..e2f0a12e097b1b 100644
--- a/clang/test/SemaOpenACC/atomic-construct.cpp
+++ b/clang/test/SemaOpenACC/atomic-construct.cpp
@@ -1891,3 +1891,29 @@ template<class T> void bar(T baz) {
baz = baz << foo;
}
}
+
+namespace gh245108 {
+template <typename T> void foo() {
+ // expected-error at +2{{statement associated with OpenACC 'atomic' directive is invalid}}
+ // expected-note at +2{{expected assignment, compound assignment, increment, or decrement expression}}
+#pragma acc atomic
+ int i;
+ // expected-error at +1{{use of undeclared identifier 'i'}}
+ i = 42;
+}
+
+void bar() { foo<int>(); }
+}
+
+namespace gh245108 {
+ template <typename T> void baz() {
+ // expected-error at +2{{statement associated with OpenACC 'atomic' directive is invalid}}
+ // expected-note at +2{{expected assignment, compound assignment, increment, or decrement expression}}
+#pragma acc atomic
+ int i;
+ // expected-error at +1{{use of undeclared identifier 'i'}}
+ i = 42;
+}
+
+void boom() { baz<int>(); }
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/245556
More information about the cfe-commits
mailing list