Skip to content

Commit d597452

Browse files
authored
[OpenMP] Fix crash with invalid argument to simd collapse (#139313)
Same as with other recent crash fixes, this is checking whether the argument expression contains errors or not. Fixes #138493
1 parent 53df640 commit d597452

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

clang/docs/ReleaseNotes.rst

+2
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,8 @@ OpenMP Support
920920
``partial`` was an invalid expression. (#GH139267)
921921
- Fixed a crashing bug with ``omp tile sizes`` if the argument to ``sizes`` was
922922
an invalid expression. (#GH139073)
923+
- Fixed a crashing bug with ``omp simd collapse`` if the argument to
924+
``collapse`` was an invalid expression. (#GH138493)
923925
- Fixed a crashing bug with ``omp distribute dist_schedule`` if the argument to
924926
``dist_schedule`` was not strictly positive. (#GH139266)
925927

clang/lib/Sema/SemaOpenMP.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -9648,6 +9648,13 @@ checkOpenMPLoop(OpenMPDirectiveKind DKind, Expr *CollapseLoopCountExpr,
96489648
DSAStackTy &DSA,
96499649
SemaOpenMP::VarsWithInheritedDSAType &VarsWithImplicitDSA,
96509650
OMPLoopBasedDirective::HelperExprs &Built) {
9651+
// If either of the loop expressions exist and contain errors, we bail out
9652+
// early because diagnostics have already been emitted and we can't reliably
9653+
// check more about the loop.
9654+
if ((CollapseLoopCountExpr && CollapseLoopCountExpr->containsErrors()) ||
9655+
(OrderedLoopCountExpr && OrderedLoopCountExpr->containsErrors()))
9656+
return 0;
9657+
96519658
unsigned NestedLoopCount = 1;
96529659
bool SupportsNonPerfectlyNested = (SemaRef.LangOpts.OpenMP >= 50) &&
96539660
!isOpenMPLoopTransformationDirective(DKind);

clang/test/OpenMP/simd_collapse_messages.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,12 @@ int main(int argc, char **argv) {
9797
return tmain<int, char, 1, 0>(argc, argv);
9898
}
9999

100+
namespace GH138493 {
101+
void f(void) {
102+
// This would previously crash when processing an invalid expression as an
103+
// argument to collapse.
104+
#pragma omp simd collapse(a) // expected-error {{use of undeclared identifier 'a'}}
105+
for (int i = 0; i < 10; i++)
106+
;
107+
}
108+
} // namespace GH138493

0 commit comments

Comments
 (0)