[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
This commit is contained in:
Aaron Ballman
2025-05-09 12:32:44 -04:00
committed by GitHub
parent 5494349a5a
commit ab6c4f5085
3 changed files with 13 additions and 1 deletions

View File

@@ -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

View File

@@ -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 {

View File

@@ -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++)
;
}
}