https://github.com/TPPPP72 updated https://github.com/llvm/llvm-project/pull/217875
>From 170ed10ff77e5e1350c3365c635b1b1fdf5b7596 Mon Sep 17 00:00:00 2001 From: Shengxin Pei <[email protected]> Date: Fri, 21 Aug 2026 18:23:59 +0800 Subject: [PATCH 1/3] [Clang][OpenMP] Fixed an assertion when `#pragma omp declare simd` or `#pragma omp declare variant` is followed by another OpenMP declarative directive containing a qualified identifier --- clang/docs/ReleaseNotes.md | 1 + clang/lib/Parse/ParseOpenMP.cpp | 16 ++++++++++++++++ clang/test/SemaOpenMP/gh217204.cpp | 11 +++++++++++ 3 files changed, 28 insertions(+) create mode 100644 clang/test/SemaOpenMP/gh217204.cpp diff --git a/clang/docs/ReleaseNotes.md b/clang/docs/ReleaseNotes.md index 8c9467ca7b742..2f70f2aa94c1f 100644 --- a/clang/docs/ReleaseNotes.md +++ b/clang/docs/ReleaseNotes.md @@ -438,6 +438,7 @@ features cannot lower the translation-unit ABI level; - Fixed a bug where preprocessor directives following comments were not correctly recognized when using -C. (#GH48361) - Fixed a crash when declaring a member template within a local class inside an OpenMP region. (#GH216052) - Fixed a bug where repeated #imports of modular headers in non-modular compilation were translated to #pragma clang module import. (#GH216924) +- Fixed an assertion when `#pragma omp declare simd` or `#pragma omp declare variant` is followed by another OpenMP declarative directive containing a qualified identifier. (#GH217204) #### Bug Fixes to Compiler Builtins diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index 30b6c64e69f4c..81084a8830c9d 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -2214,6 +2214,22 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl( << (DKind == OMPD_declare_simd ? 0 : 1); return DeclGroupPtrTy(); } + + DeclGroupRef DG = Ptr.get(); + bool HasNewDecl = false; + SourceManager &SM = PP.getSourceManager(); + for (const Decl *D : DG) { + if (SM.isBeforeInTranslationUnit(Loc, D->getBeginLoc())) { + HasNewDecl = true; + break; + } + } + if (!HasNewDecl) { + Diag(Loc, diag::err_omp_decl_in_declare_simd_variant) + << (DKind == OMPD_declare_simd ? 0 : 1); + return DeclGroupPtrTy(); + } + if (DKind == OMPD_declare_simd) return ParseOMPDeclareSimdClauses(Ptr, Toks, Loc); assert(DKind == OMPD_declare_variant && diff --git a/clang/test/SemaOpenMP/gh217204.cpp b/clang/test/SemaOpenMP/gh217204.cpp new file mode 100644 index 0000000000000..4063f38f85a0d --- /dev/null +++ b/clang/test/SemaOpenMP/gh217204.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -fopenmp -fsyntax-only -verify %s + +namespace N { + void foo(); +} + +#pragma omp declare simd // expected-error {{function declaration is expected after 'declare simd' directive}} +#pragma omp declare target to(N::foo) + +#pragma omp declare variant // expected-error {{function declaration is expected after 'declare variant' directive}} +#pragma omp declare target to(N::foo) >From 35fa3b98fe8af6537f8f920c45a1bc4d36b275b3 Mon Sep 17 00:00:00 2001 From: Shengxin Pei <[email protected]> Date: Fri, 21 Aug 2026 20:20:37 +0800 Subject: [PATCH 2/3] use lambda --- clang/lib/Parse/ParseOpenMP.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index 81084a8830c9d..37a36acfc0fbb 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -2215,16 +2215,17 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl( return DeclGroupPtrTy(); } - DeclGroupRef DG = Ptr.get(); - bool HasNewDecl = false; - SourceManager &SM = PP.getSourceManager(); - for (const Decl *D : DG) { - if (SM.isBeforeInTranslationUnit(Loc, D->getBeginLoc())) { - HasNewDecl = true; - break; + auto HasNewDecl = [&] { + DeclGroupRef DG = Ptr.get(); + SourceManager &SM = PP.getSourceManager(); + for (const Decl *D : DG) { + if (SM.isBeforeInTranslationUnit(Loc, D->getBeginLoc())) + return true; } - } - if (!HasNewDecl) { + return false; + }; + + if (!HasNewDecl()) { Diag(Loc, diag::err_omp_decl_in_declare_simd_variant) << (DKind == OMPD_declare_simd ? 0 : 1); return DeclGroupPtrTy(); >From 291bc9eb807dc03dcd0d0f2c940b1db963e607bd Mon Sep 17 00:00:00 2001 From: Shengxin Pei <[email protected]> Date: Sat, 22 Aug 2026 01:11:33 +0800 Subject: [PATCH 3/3] use any_of --- clang/lib/Parse/ParseOpenMP.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/clang/lib/Parse/ParseOpenMP.cpp b/clang/lib/Parse/ParseOpenMP.cpp index 37a36acfc0fbb..86aba1ca95341 100644 --- a/clang/lib/Parse/ParseOpenMP.cpp +++ b/clang/lib/Parse/ParseOpenMP.cpp @@ -2215,17 +2215,11 @@ Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl( return DeclGroupPtrTy(); } - auto HasNewDecl = [&] { - DeclGroupRef DG = Ptr.get(); - SourceManager &SM = PP.getSourceManager(); - for (const Decl *D : DG) { - if (SM.isBeforeInTranslationUnit(Loc, D->getBeginLoc())) - return true; - } - return false; - }; - - if (!HasNewDecl()) { + DeclGroupRef DG = Ptr.get(); + SourceManager &SM = PP.getSourceManager(); + if (!llvm::any_of(DG, [&](const Decl *D) { + return SM.isBeforeInTranslationUnit(Loc, D->getBeginLoc()); + })) { Diag(Loc, diag::err_omp_decl_in_declare_simd_variant) << (DKind == OMPD_declare_simd ? 0 : 1); return DeclGroupPtrTy(); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
