Skip to content

[OpenMP] Fix crash with invalid size expression #139745

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

Merged
merged 2 commits into from
May 13, 2025

Conversation

AaronBallman
Copy link
Collaborator

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

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 llvm#139433
@AaronBallman AaronBallman added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" crash-on-invalid clang:openmp OpenMP related changes to Clang labels May 13, 2025
@llvmbot
Copy link
Member

llvmbot commented May 13, 2025

@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/139745.diff

2 Files Affected:

  • (modified) clang/lib/Sema/SemaOpenMP.cpp (+4-1)
  • (modified) clang/test/OpenMP/stripe_messages.cpp (+8)
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index be6ce97d838f3..d9a24adc64f1b 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..a7799ec53311e 100644
--- a/clang/test/OpenMP/stripe_messages.cpp
+++ b/clang/test/OpenMP/stripe_messages.cpp
@@ -161,3 +161,11 @@ void template_inst() {
   // expected-note@+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)
+  for (int i = 0; i < 10; i++)
+    ;
+}
+} // namespace GH139433

@AaronBallman AaronBallman merged commit 131c8f8 into llvm:main May 13, 2025
8 of 10 checks passed
@AaronBallman AaronBallman deleted the aballman-gh139433 branch May 13, 2025 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:openmp OpenMP related changes to Clang clang Clang issues not falling into any other category crash-on-invalid
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[OpenMP] crash on an invalid sizes argument (stripe directive)
4 participants