Author: Aaron Ballman Date: 2025-05-09T12:32:44-04:00 New Revision: ab6c4f50852204d3a89a647af84b6ed613a2f204
URL: https://github.com/llvm/llvm-project/commit/ab6c4f50852204d3a89a647af84b6ed613a2f204 DIFF: https://github.com/llvm/llvm-project/commit/ab6c4f50852204d3a89a647af84b6ed613a2f204.diff LOG: [OpenMP] Fix a crash on invalid with unroll partial (#139280) You cannot get the integer constant expression's value if the expression contains errors. Fixes https://github.com/llvm/llvm-project/issues/139267 Added: Modified: clang/docs/ReleaseNotes.rst clang/lib/Sema/SemaOpenMP.cpp clang/test/OpenMP/unroll_messages.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e8e67e14f007b..a8f5f40d8fef7 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -905,6 +905,8 @@ OpenMP Support - Added support 'no_openmp_constructs' assumption clause. - Added support for 'self_maps' in map and requirement clause. - Added support for 'omp stripe' directive. +- Fixed a crashing bug with ``omp unroll partial`` if the argument to + ``partial`` was an invalid expression. (#GH139267) - 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 diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp index 50211c5cf3ed8..15d568fcb9cc4 100644 --- a/clang/lib/Sema/SemaOpenMP.cpp +++ b/clang/lib/Sema/SemaOpenMP.cpp @@ -14912,7 +14912,8 @@ StmtResult SemaOpenMP::ActOnOpenMPUnrollDirective(ArrayRef<OMPClause *> Clauses, // Determine the unroll factor. uint64_t Factor; SourceLocation FactorLoc; - if (Expr *FactorVal = PartialClause->getFactor()) { + if (Expr *FactorVal = PartialClause->getFactor(); + FactorVal && !FactorVal->containsErrors()) { Factor = FactorVal->getIntegerConstantExpr(Context)->getZExtValue(); FactorLoc = FactorVal->getExprLoc(); } else { diff --git a/clang/test/OpenMP/unroll_messages.cpp b/clang/test/OpenMP/unroll_messages.cpp index 75bca4b8ad1e0..17d5ed83e162f 100644 --- a/clang/test/OpenMP/unroll_messages.cpp +++ b/clang/test/OpenMP/unroll_messages.cpp @@ -128,3 +128,12 @@ void template_inst(int n) { // expected-note@+1 {{in instantiation of function template specialization 'templated_func<int, -1>' requested here}} templated_func<int, -1>(n); } + +namespace GH139267 { +void f(void) { + // This would previously crash with follow-on recovery after issuing the error. +#pragma omp unroll partial(a) // expected-error {{use of undeclared identifier 'a'}} + for (int i = 0; i < 10; i++) + ; +} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits