[clang] 131c8f8 - [OpenMP] Fix crash with invalid size expression (#139745)
via cfe-commits
cfe-commits at lists.llvm.org
Tue May 13 09:55:57 PDT 2025
Author: Aaron Ballman
Date: 2025-05-13T12:55:53-04:00
New Revision: 131c8f84bb4799ba8dded520791115b3c2b94f29
URL: https://github.com/llvm/llvm-project/commit/131c8f84bb4799ba8dded520791115b3c2b94f29
DIFF: https://github.com/llvm/llvm-project/commit/131c8f84bb4799ba8dded520791115b3c2b94f29.diff
LOG: [OpenMP] Fix crash with invalid size expression (#139745)
We weren't correctly handling size expressions with errors before trying
to get the type of the size expression.
No release note needed because support for 'stripe' was added to the
current release.
Fixes #139433
Added:
Modified:
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/stripe_messages.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index fcb556f8f2b9f..f16f841d62edd 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -14551,7 +14551,10 @@ StmtResult SemaOpenMP::ActOnOpenMPStripeDirective(ArrayRef<OMPClause *> Clauses,
const auto *SizesClause =
OMPExecutableDirective::getSingleClause<OMPSizesClause>(Clauses);
- if (!SizesClause || llvm::is_contained(SizesClause->getSizesRefs(), nullptr))
+ if (!SizesClause ||
+ llvm::any_of(SizesClause->getSizesRefs(), [](const Expr *SizeExpr) {
+ return !SizeExpr || SizeExpr->containsErrors();
+ }))
return StmtError();
unsigned NumLoops = SizesClause->getNumSizes();
diff --git a/clang/test/OpenMP/stripe_messages.cpp b/clang/test/OpenMP/stripe_messages.cpp
index d05b8566f11de..3f171f40d71d9 100644
--- a/clang/test/OpenMP/stripe_messages.cpp
+++ b/clang/test/OpenMP/stripe_messages.cpp
@@ -161,3 +161,11 @@ void template_inst() {
// expected-note at +1 {{in instantiation of function template specialization 'templated_func_type_dependent<int>' requested here}}
templated_func_type_dependent<int>();
}
+
+namespace GH139433 {
+void f() {
+#pragma omp stripe sizes(a) // expected-error {{use of undeclared identifier 'a'}}
+ for (int i = 0; i < 10; i++)
+ ;
+}
+} // namespace GH139433
More information about the cfe-commits
mailing list