Author: Aaron Ballman
Date: 2025-05-09T11:12:19-04:00
New Revision: b249b49c133d0b4e1e2505dfd0a53f4da50d2a7a

URL: 
https://github.com/llvm/llvm-project/commit/b249b49c133d0b4e1e2505dfd0a53f4da50d2a7a
DIFF: 
https://github.com/llvm/llvm-project/commit/b249b49c133d0b4e1e2505dfd0a53f4da50d2a7a.diff

LOG: [OpenMP] Fix crash when diagnosing dist_schedule (#139277)

We were failing to pass a required argument when emitting the
diagnostic, so the source range was being used in place of an index.
This caused a failed assertion due to the incorrect index.

Fixes #139266

Added: 
    

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Sema/SemaOpenMP.cpp
    clang/test/OpenMP/teams_distribute_dist_schedule_messages.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6c32a7e9a5613..f7d56cfd19ce5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -903,6 +903,8 @@ OpenMP Support
 - Added support for 'omp stripe' directive.
 - Fixed a crashing bug with ``omp tile sizes`` if the argument to ``sizes`` was
   an invalid expression. (#GH139073)
+- Fixed a crashing bug with ``omp distribute dist_schedule`` if the argument to
+  ``dist_schedule`` was not strictly positive. (#GH139266)
 
 Improvements
 ^^^^^^^^^^^^

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 90437fc03f3dc..50211c5cf3ed8 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -22789,7 +22789,8 @@ OMPClause *SemaOpenMP::ActOnOpenMPDistScheduleClause(
               ValExpr->getIntegerConstantExpr(getASTContext())) {
         if (Result->isSigned() && !Result->isStrictlyPositive()) {
           Diag(ChunkSizeLoc, diag::err_omp_negative_expression_in_clause)
-              << "dist_schedule" << ChunkSize->getSourceRange();
+              << "dist_schedule" << /*strictly positive*/ 1
+              << ChunkSize->getSourceRange();
           return nullptr;
         }
       } else if (getOpenMPCaptureRegionForClause(

diff  --git a/clang/test/OpenMP/teams_distribute_dist_schedule_messages.cpp 
b/clang/test/OpenMP/teams_distribute_dist_schedule_messages.cpp
index 22d2408d3f178..72d8e33173d71 100644
--- a/clang/test/OpenMP/teams_distribute_dist_schedule_messages.cpp
+++ b/clang/test/OpenMP/teams_distribute_dist_schedule_messages.cpp
@@ -105,3 +105,11 @@ int main(int argc, char **argv) {
 
   return (tmain<int, 5>(argc) + tmain<char, 1>(argv[0][0])); // expected-note 
{{in instantiation of function template specialization 'tmain<int, 5>' 
requested here}} expected-note {{in instantiation of function template 
specialization 'tmain<char, 1>' requested here}}
 }
+
+namespace GH139266 {
+void f(void) {
+#pragma omp distribute dist_schedule(static, 0) // expected-error {[argument 
to 'dist_schedule' clause must be a strictly positive integer value}}
+  for (int i = 0; i < 10; i++)
+    ;
+}
+} // namespace GH139266


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to