Skip to content

Commit ab6c4f5

Browse files
authored
[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 #139267
1 parent 5494349 commit ab6c4f5

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

clang/docs/ReleaseNotes.rst

+2
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,8 @@ OpenMP Support
905905
- Added support 'no_openmp_constructs' assumption clause.
906906
- Added support for 'self_maps' in map and requirement clause.
907907
- Added support for 'omp stripe' directive.
908+
- Fixed a crashing bug with ``omp unroll partial`` if the argument to
909+
``partial`` was an invalid expression. (#GH139267)
908910
- Fixed a crashing bug with ``omp tile sizes`` if the argument to ``sizes`` was
909911
an invalid expression. (#GH139073)
910912
- Fixed a crashing bug with ``omp distribute dist_schedule`` if the argument to

clang/lib/Sema/SemaOpenMP.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -14912,7 +14912,8 @@ StmtResult SemaOpenMP::ActOnOpenMPUnrollDirective(ArrayRef<OMPClause *> Clauses,
1491214912
// Determine the unroll factor.
1491314913
uint64_t Factor;
1491414914
SourceLocation FactorLoc;
14915-
if (Expr *FactorVal = PartialClause->getFactor()) {
14915+
if (Expr *FactorVal = PartialClause->getFactor();
14916+
FactorVal && !FactorVal->containsErrors()) {
1491614917
Factor = FactorVal->getIntegerConstantExpr(Context)->getZExtValue();
1491714918
FactorLoc = FactorVal->getExprLoc();
1491814919
} else {

clang/test/OpenMP/unroll_messages.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,12 @@ void template_inst(int n) {
128128
// expected-note@+1 {{in instantiation of function template specialization 'templated_func<int, -1>' requested here}}
129129
templated_func<int, -1>(n);
130130
}
131+
132+
namespace GH139267 {
133+
void f(void) {
134+
// This would previously crash with follow-on recovery after issuing the error.
135+
#pragma omp unroll partial(a) // expected-error {{use of undeclared identifier 'a'}}
136+
for (int i = 0; i < 10; i++)
137+
;
138+
}
139+
}

0 commit comments

Comments
 (0)