Skip to content

Commit c8d68af

Browse files
committed
Minor fixes
1 parent f1d3fca commit c8d68af

File tree

2 files changed

+31
-39
lines changed

2 files changed

+31
-39
lines changed

clang/include/clang/Sema/SemaOpenMP.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,7 +1495,7 @@ class SemaOpenMP : public SemaBase {
14951495
Stmt *&Body, SmallVectorImpl<SmallVector<Stmt *>> &OriginalInits);
14961496

14971497
/// Categories of loops encountered during semantic OpenMP loop
1498-
/// analysis
1498+
/// analysis.
14991499
///
15001500
/// This enumeration identifies the structural category of a loop or sequence
15011501
/// of loops analyzed in the context of OpenMP transformations and directives.
@@ -1505,12 +1505,12 @@ class SemaOpenMP : public SemaBase {
15051505
/// @var OMPLoopCategory::RegularLoop
15061506
/// Represents a standard canonical loop nest found in the
15071507
/// original source code or an intact loop after transformations
1508-
/// (i.e Post/Pre loops of a loopranged fusion)
1508+
/// (i.e Post/Pre loops of a loopranged fusion).
15091509
RegularLoop,
15101510

15111511
/// @var OMPLoopCategory::TransformSingleLoop
15121512
/// Represents the resulting loop structure when an OpenMP loop
1513-
// transformation, generates a single, top-level loop
1513+
/// transformation, generates a single, top-level loop.
15141514
TransformSingleLoop,
15151515
};
15161516

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14313,7 +14313,7 @@ bool SemaOpenMP::checkTransformableLoopNest(
1431314313
/// }
1431414314
/// }
1431514315
/// }
14316-
/// Result: Loop 'i' contains 2 loops, Loop 'r' also contains 2 loops
14316+
/// Result: Loop 'i' contains 2 loops, Loop 'r' also contains 2 loops.
1431714317
class NestedLoopCounterVisitor final : public DynamicRecursiveASTVisitor {
1431814318
private:
1431914319
unsigned NestedLoopCount = 0;
@@ -14341,24 +14341,24 @@ class NestedLoopCounterVisitor final : public DynamicRecursiveASTVisitor {
1434114341
// LambdaExpr, StmtExpr, BlockExpr, and RequiresExpr. These expressions
1434214342
// may contain inner statements (and even loops), but they are not part
1434314343
// of the syntactic body of the surrounding loop structure.
14344-
// Therefore must not be counted
14344+
// Therefore must not be counted.
1434514345
if (isa<Expr>(S))
1434614346
return true;
1434714347

14348-
// Only recurse into CompoundStmt (block {}) and loop bodies
14348+
// Only recurse into CompoundStmt (block {}) and loop bodies.
1434914349
if (isa<CompoundStmt, ForStmt, CXXForRangeStmt>(S)) {
1435014350
return DynamicRecursiveASTVisitor::TraverseStmt(S);
1435114351
}
1435214352

1435314353
// Stop traversal of the rest of statements, that break perfect
14354-
// loop nesting, such as control flow (IfStmt, SwitchStmt...)
14354+
// loop nesting, such as control flow (IfStmt, SwitchStmt...).
1435514355
return true;
1435614356
}
1435714357

1435814358
bool TraverseDecl(Decl *D) override {
1435914359
// Stop in the case of finding a declaration, it is not important
1436014360
// in order to find nested loops (Possible CXXRecordDecl, RecordDecl,
14361-
// FunctionDecl...)
14361+
// FunctionDecl...).
1436214362
return true;
1436314363
}
1436414364
};
@@ -14370,7 +14370,7 @@ bool SemaOpenMP::analyzeLoopSequence(Stmt *LoopSeqStmt,
1437014370

1437114371
VarsWithInheritedDSAType TmpDSA;
1437214372
/// Helper Lambda to handle storing initialization and body statements for
14373-
/// both ForStmt and CXXForRangeStmt
14373+
/// both ForStmt and CXXForRangeStmt.
1437414374
auto StoreLoopStatements = [](LoopAnalysis &Analysis, Stmt *LoopStmt) {
1437514375
if (auto *For = dyn_cast<ForStmt>(LoopStmt)) {
1437614376
Analysis.OriginalInits.push_back(For->getInit());
@@ -14384,7 +14384,7 @@ bool SemaOpenMP::analyzeLoopSequence(Stmt *LoopSeqStmt,
1438414384

1438514385
/// Helper lambda functions to encapsulate the processing of different
1438614386
/// derivations of the canonical loop sequence grammar
14387-
/// Modularized code for handling loop generation and transformations
14387+
/// Modularized code for handling loop generation and transformations.
1438814388
auto AnalyzeLoopGeneration = [&](Stmt *Child) {
1438914389
auto *LoopTransform = dyn_cast<OMPLoopTransformationDirective>(Child);
1439014390
Stmt *TransformedStmt = LoopTransform->getTransformedStmt();
@@ -14442,7 +14442,7 @@ bool SemaOpenMP::analyzeLoopSequence(Stmt *LoopSeqStmt,
1444214442
return true;
1444314443
};
1444414444

14445-
/// Modularized code for handling regular canonical loops
14445+
/// Modularized code for handling regular canonical loops.
1444614446
auto AnalyzeRegularLoop = [&](Stmt *Child) {
1444714447
LoopAnalysis &NewRegularLoop =
1444814448
SeqAnalysis.Loops.emplace_back(OMPLoopCategory::RegularLoop);
@@ -14463,55 +14463,47 @@ bool SemaOpenMP::analyzeLoopSequence(Stmt *LoopSeqStmt,
1446314463
return true;
1446414464
};
1446514465

14466-
/// Helper functions to validate loop sequence grammar derivations
14466+
/// Helper functions to validate loop sequence grammar derivations.
1446714467
auto IsLoopSequenceDerivation = [](auto *Child) {
1446814468
return isa<ForStmt, CXXForRangeStmt, OMPLoopTransformationDirective>(Child);
1446914469
};
14470-
/// Helper functions to validate loop generating grammar derivations
14470+
/// Helper functions to validate loop generating grammar derivations.
1447114471
auto IsLoopGeneratingStmt = [](auto *Child) {
1447214472
return isa<OMPLoopTransformationDirective>(Child);
1447314473
};
1447414474

14475-
// High level grammar validation
14475+
// High level grammar validation.
1447614476
for (auto *Child : LoopSeqStmt->children()) {
14477-
1447814477
if (!Child)
1447914478
continue;
14480-
14481-
// Skip over non-loop-sequence statements
14479+
// Skip over non-loop-sequence statements.
1448214480
if (!IsLoopSequenceDerivation(Child)) {
1448314481
Child = Child->IgnoreContainers();
14484-
14485-
// Ignore empty compound statement
14482+
// Ignore empty compound statement.
1448614483
if (!Child)
1448714484
continue;
14488-
1448914485
// In the case of a nested loop sequence ignoring containers would not
14490-
// be enough, a recurisve transversal of the loop sequence is required
14486+
// be enough, a recurisve transversal of the loop sequence is required.
1449114487
if (isa<CompoundStmt>(Child)) {
1449214488
if (!analyzeLoopSequence(Child, SeqAnalysis, Context, Kind))
1449314489
return false;
1449414490
// Already been treated, skip this children
1449514491
continue;
1449614492
}
1449714493
}
14498-
// Regular loop sequence handling
14494+
// Regular loop sequence handling.
1449914495
if (IsLoopSequenceDerivation(Child)) {
1450014496
if (IsLoopGeneratingStmt(Child)) {
1450114497
if (!AnalyzeLoopGeneration(Child))
1450214498
return false;
14503-
14504-
// AnalyzeLoopGeneration updates Loop Sequence size accordingly
14505-
14499+
// AnalyzeLoopGeneration updates SeqAnalysis.LoopSeqSize accordingly.
1450614500
} else {
1450714501
if (!AnalyzeRegularLoop(Child))
1450814502
return false;
14509-
14510-
// Update the Loop Sequence size by one
1451114503
SeqAnalysis.LoopSeqSize++;
1451214504
}
1451314505
} else {
14514-
// Report error for invalid statement inside canonical loop sequence
14506+
// Report error for invalid statement inside canonical loop sequence.
1451514507
Diag(Child->getBeginLoc(), diag::err_omp_not_for)
1451614508
<< 0 << getOpenMPDirectiveName(Kind);
1451714509
return false;
@@ -14523,14 +14515,6 @@ bool SemaOpenMP::analyzeLoopSequence(Stmt *LoopSeqStmt,
1452314515
bool SemaOpenMP::checkTransformableLoopSequence(
1452414516
OpenMPDirectiveKind Kind, Stmt *AStmt, LoopSequenceAnalysis &SeqAnalysis,
1452514517
ASTContext &Context) {
14526-
14527-
// Checks whether the given statement is a compound statement
14528-
if (!isa<CompoundStmt>(AStmt)) {
14529-
Diag(AStmt->getBeginLoc(), diag::err_omp_not_a_loop_sequence)
14530-
<< getOpenMPDirectiveName(Kind);
14531-
return false;
14532-
}
14533-
1453414518
// Following OpenMP 6.0 API Specification, a Canonical Loop Sequence follows
1453514519
// the grammar:
1453614520
//
@@ -14543,17 +14527,25 @@ bool SemaOpenMP::checkTransformableLoopSequence(
1454314527
// 2. loop-nest
1454414528
// 3. loop-sequence-generating-construct (i.e OMPLoopTransformationDirective)
1454514529
//
14546-
// To recognise and traverse this structure the following helper functions
14547-
// have been defined. analyzeLoopSequence serves as the recurisve entry point
14530+
// To recognise and traverse this structure the helper function
14531+
// analyzeLoopSequence serves as the recurisve entry point
1454814532
// and tries to match the input AST to the canonical loop sequence grammar
1454914533
// structure. This function will perform both a semantic and syntactical
1455014534
// analysis of the given statement according to OpenMP 6.0 definition of
14551-
// the aforementioned canonical loop sequence
14535+
// the aforementioned canonical loop sequence.
14536+
14537+
// We expect an outer compound statement.
14538+
if (!isa<CompoundStmt>(AStmt)) {
14539+
Diag(AStmt->getBeginLoc(), diag::err_omp_not_a_loop_sequence)
14540+
<< getOpenMPDirectiveName(Kind);
14541+
return false;
14542+
}
1455214543

1455314544
// Recursive entry point to process the main loop sequence
1455414545
if (!analyzeLoopSequence(AStmt, SeqAnalysis, Context, Kind))
1455514546
return false;
1455614547

14548+
// Diagnose an empty loop sequence.
1455714549
if (SeqAnalysis.LoopSeqSize <= 0) {
1455814550
Diag(AStmt->getBeginLoc(), diag::err_omp_empty_loop_sequence)
1455914551
<< getOpenMPDirectiveName(Kind);

0 commit comments

Comments
 (0)