Skip to content

Commit 6ea754b

Browse files
committed
[OpenMP] Fix a crash on invalid with unroll partial
You cannot get the integer constant expression's value if the expression contains errors. Fixes #139267
1 parent 4c69f82 commit 6ea754b

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,8 @@ OpenMP Support
901901
- Added support 'no_openmp_constructs' assumption clause.
902902
- Added support for 'self_maps' in map and requirement clause.
903903
- Added support for 'omp stripe' directive.
904+
- Fixed a crashing bug with ``omp unroll partial`` if the argument to
905+
``partial`` was an invalid expression. (#GH139267)
904906
- Fixed a crashing bug with ``omp tile sizes`` if the argument to ``sizes`` was
905907
an invalid expression. (#GH139073)
906908

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14887,7 +14887,8 @@ StmtResult SemaOpenMP::ActOnOpenMPUnrollDirective(ArrayRef<OMPClause *> Clauses,
1488714887
// Determine the unroll factor.
1488814888
uint64_t Factor;
1488914889
SourceLocation FactorLoc;
14890-
if (Expr *FactorVal = PartialClause->getFactor()) {
14890+
if (Expr *FactorVal = PartialClause->getFactor();
14891+
FactorVal && !FactorVal->containsErrors()) {
1489114892
Factor = FactorVal->getIntegerConstantExpr(Context)->getZExtValue();
1489214893
FactorLoc = FactorVal->getExprLoc();
1489314894
} else {

clang/test/OpenMP/unroll_messages.cpp

Lines changed: 9 additions & 0 deletions
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)