[OPENMP] Add a check for iterator not reached the end of stack, NFC.
Add an extra check for the iterator during checks of the data-sharing
attributes.
llvm-svn: 301549
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 9a19023..43fd055 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -828,14 +828,14 @@
? std::next(Stack.back().first.rbegin())
: Stack.back().first.rbegin();
auto EndI = Stack.back().first.rend();
- do {
+ while (std::distance(I, EndI) > 1) {
std::advance(I, 1);
if (!DPred(I->Directive) && !isParallelOrTaskRegion(I->Directive))
continue;
DSAVarData DVar = getDSA(I, D);
if (CPred(DVar.CKind))
return DVar;
- } while (std::distance(I, EndI) > 1);
+ }
return {};
}