[clang] [OpenACC] Fix invalid using inside of an openacc directive (PR #198058)
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Fri May 15 19:50:53 PDT 2026
https://github.com/erichkeane created https://github.com/llvm/llvm-project/pull/198058
Bug report #197858 comes up with a reproducer where an invalid `using` declaration checks the Scope it is in, and asserts if it isn't in a DeclScope. Since all of the important directives that create scopes end up causing a new scope anyway, this patch adds 'DeclScope' to the parse scope for an OpenACC directive. This follows the guidance of the OpenMP directives.
Fixes: #197858
>From e717f6b964b6c5de8c27c210648ea590f5048ead Mon Sep 17 00:00:00 2001
From: Erich Keane <erich.keane at verizon.net>
Date: Fri, 15 May 2026 19:11:52 -0700
Subject: [PATCH] [OpenACC] Fix invalid using inside of an openacc directive
Bug report #197858 comes up with a reproducer where an invalid `using`
declaration checks the Scope it is in, and asserts if it isn't in a
DeclScope. Since all of the important directives that create scopes end
up causing a new scope anyway, this patch adds 'DeclScope' to the parse
scope for an OpenACC directive. This follows the guidance of the OpenMP
directives.
Fixes: #197858
---
clang/lib/Parse/ParseOpenACC.cpp | 6 +++---
clang/test/ParserOpenACC/gh197858.cpp | 10 ++++++++++
2 files changed, 13 insertions(+), 3 deletions(-)
create mode 100644 clang/test/ParserOpenACC/gh197858.cpp
diff --git a/clang/lib/Parse/ParseOpenACC.cpp b/clang/lib/Parse/ParseOpenACC.cpp
index b79a956d51505..a95c5730a001c 100644
--- a/clang/lib/Parse/ParseOpenACC.cpp
+++ b/clang/lib/Parse/ParseOpenACC.cpp
@@ -608,18 +608,18 @@ unsigned getOpenACCScopeFlags(OpenACCDirectiveKind DirKind) {
case OpenACCDirectiveKind::Kernels:
// Mark this as a BreakScope/ContinueScope as well as a compute construct
// so that we can diagnose trying to 'break'/'continue' inside of one.
- return Scope::BreakScope | Scope::ContinueScope |
+ return Scope::BreakScope | Scope::ContinueScope | Scope::DeclScope |
Scope::OpenACCComputeConstructScope;
case OpenACCDirectiveKind::ParallelLoop:
case OpenACCDirectiveKind::SerialLoop:
case OpenACCDirectiveKind::KernelsLoop:
// Mark this as a BreakScope/ContinueScope as well as a compute construct
// so that we can diagnose trying to 'break'/'continue' inside of one.
- return Scope::BreakScope | Scope::ContinueScope |
+ return Scope::BreakScope | Scope::ContinueScope | Scope::DeclScope |
Scope::OpenACCComputeConstructScope |
Scope::OpenACCLoopConstructScope;
case OpenACCDirectiveKind::Loop:
- return Scope::OpenACCLoopConstructScope;
+ return Scope::DeclScope | Scope::OpenACCLoopConstructScope;
case OpenACCDirectiveKind::Data:
case OpenACCDirectiveKind::EnterData:
case OpenACCDirectiveKind::ExitData:
diff --git a/clang/test/ParserOpenACC/gh197858.cpp b/clang/test/ParserOpenACC/gh197858.cpp
new file mode 100644
index 0000000000000..20046d79c3f16
--- /dev/null
+++ b/clang/test/ParserOpenACC/gh197858.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 %s -verify -fopenacc
+
+void func() {
+#pragma acc parallel
+ using i; // expected-error{{using declaration requires a qualified name}}
+#pragma acc loop
+ using j; // expected-error{{using declaration requires a qualified name}}
+#pragma acc parallel loop
+ using k; // expected-error{{using declaration requires a qualified name}}
+}
More information about the cfe-commits
mailing list