Skip to content

Commit 422ffd7

Browse files
committed
Fixed formatting and comments
1 parent 823bc08 commit 422ffd7

File tree

1 file changed

+58
-54
lines changed

1 file changed

+58
-54
lines changed

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 58 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14160,42 +14160,43 @@ StmtResult SemaOpenMP::ActOnOpenMPTargetTeamsDistributeSimdDirective(
1416014160
}
1416114161

1416214162
// Overloaded base case function
14163-
template <typename T, typename F>
14164-
static bool tryHandleAs(T *t, F &&) {
14165-
return false;
14163+
template <typename T, typename F> static bool tryHandleAs(T *t, F &&) {
14164+
return false;
1416614165
}
1416714166

1416814167
/**
14169-
* Tries to recursively cast `t` to one of the given types and invokes `f` if successful.
14168+
* Tries to recursively cast `t` to one of the given types and invokes `f` if
14169+
* successful.
1417014170
*
1417114171
* @tparam Class The first type to check.
1417214172
* @tparam Rest The remaining types to check.
1417314173
* @tparam T The base type of `t`.
14174-
* @tparam F The callable type for the function to invoke upon a successful cast.
14174+
* @tparam F The callable type for the function to invoke upon a successful
14175+
* cast.
1417514176
* @param t The object to be checked.
1417614177
* @param f The function to invoke if `t` matches `Class`.
1417714178
* @return `true` if `t` matched any type and `f` was called, otherwise `false`.
1417814179
*/
1417914180
template <typename Class, typename... Rest, typename T, typename F>
1418014181
static bool tryHandleAs(T *t, F &&f) {
14181-
if (Class *c = dyn_cast<Class>(t)) {
14182-
f(c);
14183-
return true;
14184-
} else {
14185-
return tryHandleAs<Rest...>(t, std::forward<F>(f));
14186-
}
14182+
if (Class *c = dyn_cast<Class>(t)) {
14183+
f(c);
14184+
return true;
14185+
} else {
14186+
return tryHandleAs<Rest...>(t, std::forward<F>(f));
14187+
}
1418714188
}
1418814189

1418914190
// Updates OriginalInits by checking Transform against loop transformation
1419014191
// directives and appending their pre-inits if a match is found.
1419114192
static void updatePreInits(OMPLoopBasedDirective *Transform,
1419214193
SmallVectorImpl<SmallVector<Stmt *, 0>> &PreInits) {
14193-
if (!tryHandleAs<OMPTileDirective, OMPUnrollDirective, OMPReverseDirective,
14194-
OMPInterchangeDirective, OMPFuseDirective>(
14195-
Transform, [&PreInits](auto *Dir) {
14196-
appendFlattenedStmtList(PreInits.back(), Dir->getPreInits());
14197-
}))
14198-
llvm_unreachable("Unhandled loop transformation");
14194+
if (!tryHandleAs<OMPTileDirective, OMPUnrollDirective, OMPReverseDirective,
14195+
OMPInterchangeDirective, OMPFuseDirective>(
14196+
Transform, [&PreInits](auto *Dir) {
14197+
appendFlattenedStmtList(PreInits.back(), Dir->getPreInits());
14198+
}))
14199+
llvm_unreachable("Unhandled loop transformation");
1419914200
}
1420014201

1420114202
bool SemaOpenMP::checkTransformableLoopNest(
@@ -14273,43 +14274,42 @@ class NestedLoopCounterVisitor : public DynamicRecursiveASTVisitor {
1427314274
unsigned getNestedLoopCount() const { return NestedLoopCount; }
1427414275

1427514276
bool VisitForStmt(ForStmt *FS) override {
14276-
++NestedLoopCount;
14277-
return true;
14277+
++NestedLoopCount;
14278+
return true;
1427814279
}
1427914280

1428014281
bool VisitCXXForRangeStmt(CXXForRangeStmt *FRS) override {
14281-
++NestedLoopCount;
14282-
return true;
14282+
++NestedLoopCount;
14283+
return true;
1428314284
}
1428414285

1428514286
bool TraverseStmt(Stmt *S) override {
14286-
if (!S)
14287+
if (!S)
1428714288
return true;
1428814289

14289-
// Skip traversal of all expressions, including special cases like
14290-
// LambdaExpr, StmtExpr, BlockExpr, and RequiresExpr. These expressions
14291-
// may contain inner statements (and even loops), but they are not part
14292-
// of the syntactic body of the surrounding loop structure.
14293-
// Therefore must not be counted
14294-
if (isa<Expr>(S))
14290+
// Skip traversal of all expressions, including special cases like
14291+
// LambdaExpr, StmtExpr, BlockExpr, and RequiresExpr. These expressions
14292+
// may contain inner statements (and even loops), but they are not part
14293+
// of the syntactic body of the surrounding loop structure.
14294+
// Therefore must not be counted
14295+
if (isa<Expr>(S))
1429514296
return true;
1429614297

14297-
// Only recurse into CompoundStmt (block {}) and loop bodies
14298-
if (isa<CompoundStmt>(S) || isa<ForStmt>(S) ||
14299-
isa<CXXForRangeStmt>(S)) {
14298+
// Only recurse into CompoundStmt (block {}) and loop bodies
14299+
if (isa<CompoundStmt>(S) || isa<ForStmt>(S) || isa<CXXForRangeStmt>(S)) {
1430014300
return DynamicRecursiveASTVisitor::TraverseStmt(S);
14301-
}
14301+
}
1430214302

14303-
// Stop traversal of the rest of statements, that break perfect
14304-
// loop nesting, such as control flow (IfStmt, SwitchStmt...)
14305-
return true;
14303+
// Stop traversal of the rest of statements, that break perfect
14304+
// loop nesting, such as control flow (IfStmt, SwitchStmt...)
14305+
return true;
1430614306
}
1430714307

1430814308
bool TraverseDecl(Decl *D) override {
14309-
// Stop in the case of finding a declaration, it is not important
14310-
// in order to find nested loops (Possible CXXRecordDecl, RecordDecl,
14311-
// FunctionDecl...)
14312-
return true;
14309+
// Stop in the case of finding a declaration, it is not important
14310+
// in order to find nested loops (Possible CXXRecordDecl, RecordDecl,
14311+
// FunctionDecl...)
14312+
return true;
1431314313
}
1431414314
};
1431514315

@@ -14467,15 +14467,14 @@ bool SemaOpenMP::analyzeLoopSequence(
1446714467
return isa<OMPLoopTransformationDirective>(Child);
1446814468
};
1446914469

14470-
1447114470
// High level grammar validation
1447214471
for (auto *Child : LoopSeqStmt->children()) {
1447314472

14474-
if (!Child)
14473+
if (!Child)
1447514474
continue;
1447614475

14477-
// Skip over non-loop-sequence statements
14478-
if (!isLoopSequenceDerivation(Child)) {
14476+
// Skip over non-loop-sequence statements
14477+
if (!isLoopSequenceDerivation(Child)) {
1447914478
Child = Child->IgnoreContainers();
1448014479

1448114480
// Ignore empty compound statement
@@ -14493,9 +14492,9 @@ bool SemaOpenMP::analyzeLoopSequence(
1449314492
// Already been treated, skip this children
1449414493
continue;
1449514494
}
14496-
}
14497-
// Regular loop sequence handling
14498-
if (isLoopSequenceDerivation(Child)) {
14495+
}
14496+
// Regular loop sequence handling
14497+
if (isLoopSequenceDerivation(Child)) {
1449914498
if (isLoopGeneratingStmt(Child)) {
1450014499
if (!analyzeLoopGeneration(Child)) {
1450114500
return false;
@@ -14509,12 +14508,12 @@ bool SemaOpenMP::analyzeLoopSequence(
1450914508
// Update the Loop Sequence size by one
1451014509
++LoopSeqSize;
1451114510
}
14512-
} else {
14511+
} else {
1451314512
// Report error for invalid statement inside canonical loop sequence
1451414513
Diag(Child->getBeginLoc(), diag::err_omp_not_for)
1451514514
<< 0 << getOpenMPDirectiveName(Kind);
1451614515
return false;
14517-
}
14516+
}
1451814517
}
1451914518
return true;
1452014519
}
@@ -14531,9 +14530,9 @@ bool SemaOpenMP::checkTransformableLoopSequence(
1453114530

1453214531
// Checks whether the given statement is a compound statement
1453314532
if (!isa<CompoundStmt>(AStmt)) {
14534-
Diag(AStmt->getBeginLoc(), diag::err_omp_not_a_loop_sequence)
14535-
<< getOpenMPDirectiveName(Kind);
14536-
return false;
14533+
Diag(AStmt->getBeginLoc(), diag::err_omp_not_a_loop_sequence)
14534+
<< getOpenMPDirectiveName(Kind);
14535+
return false;
1453714536
}
1453814537
// Number of top level canonical loop nests observed (And acts as index)
1453914538
LoopSeqSize = 0;
@@ -14564,7 +14563,7 @@ bool SemaOpenMP::checkTransformableLoopSequence(
1456414563
OriginalInits, TransformsPreInits,
1456514564
LoopSequencePreInits, LoopCategories, Context,
1456614565
Kind)) {
14567-
return false;
14566+
return false;
1456814567
}
1456914568
if (LoopSeqSize <= 0) {
1457014569
Diag(AStmt->getBeginLoc(), diag::err_omp_empty_loop_sequence)
@@ -15278,7 +15277,7 @@ StmtResult SemaOpenMP::ActOnOpenMPUnrollDirective(ArrayRef<OMPClause *> Clauses,
1527815277
Stmt *LoopStmt = nullptr;
1527915278
collectLoopStmts(AStmt, {LoopStmt});
1528015279

15281-
// Determine the PreInit declarations.e
15280+
// Determine the PreInit declarations.
1528215281
SmallVector<Stmt *, 4> PreInits;
1528315282
addLoopPreInits(Context, LoopHelper, LoopStmt, OriginalInits[0], PreInits);
1528415283

@@ -15894,13 +15893,18 @@ StmtResult SemaOpenMP::ActOnOpenMPFuseDirective(ArrayRef<OMPClause *> Clauses,
1589415893
CountVal = CountInt.getZExtValue();
1589515894
};
1589615895

15897-
// Checks if the loop range is valid
15896+
// OpenMP [6.0, Restrictions]
15897+
// first + count - 1 must not evaluate to a value greater than the
15898+
// loop sequence length of the associated canonical loop sequence.
1589815899
auto ValidLoopRange = [](uint64_t FirstVal, uint64_t CountVal,
1589915900
unsigned NumLoops) -> bool {
1590015901
return FirstVal + CountVal - 1 <= NumLoops;
1590115902
};
1590215903
uint64_t FirstVal = 1, CountVal = 0, LastVal = LoopSeqSize;
1590315904

15905+
// Validates the loop range after evaluating the semantic information
15906+
// and ensures that the range is valid for the given loop sequence size.
15907+
// Expressions are evaluated at compile time to obtain constant values.
1590415908
if (LRC) {
1590515909
EvaluateLoopRangeArguments(LRC->getFirst(), LRC->getCount(), FirstVal,
1590615910
CountVal);

0 commit comments

Comments
 (0)