Skip to content

Commit 7a0fd97

Browse files
authored
[NFC][CLANG] Rename duplicate loop attributes diagnostic functions (#75657)
This patch renames CheckForDuplicateCodeAlignAttrs() to CheckForDuplicateLoopAttrs() and corresponding other functions that call it to be used for other statement attributes in future.
1 parent 5545b25 commit 7a0fd97

File tree

3 files changed

+12
-13
lines changed

3 files changed

+12
-13
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2102,7 +2102,7 @@ class Sema final {
21022102
SourceLocation AttrLoc);
21032103

21042104
CodeAlignAttr *BuildCodeAlignAttr(const AttributeCommonInfo &CI, Expr *E);
2105-
bool CheckRebuiltCodeAlignStmtAttributes(ArrayRef<const Attr *> Attrs);
2105+
bool CheckRebuiltStmtAttributes(ArrayRef<const Attr *> Attrs);
21062106

21072107
bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc);
21082108

clang/lib/Sema/SemaStmtAttr.cpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,10 @@ static Attr *handleCodeAlignAttr(Sema &S, Stmt *St, const ParsedAttr &A) {
361361
}
362362

363363
// Diagnose non-identical duplicates as a 'conflicting' loop attributes
364-
// and suppress duplicate errors in cases where the two match for
365-
// [[clang::code_align()]] attribute.
366-
static void CheckForDuplicateCodeAlignAttrs(Sema &S,
367-
ArrayRef<const Attr *> Attrs) {
368-
auto FindFunc = [](const Attr *A) { return isa<const CodeAlignAttr>(A); };
364+
// and suppress duplicate errors in cases where the two match.
365+
template <typename LoopAttrT>
366+
static void CheckForDuplicateLoopAttrs(Sema &S, ArrayRef<const Attr *> Attrs) {
367+
auto FindFunc = [](const Attr *A) { return isa<const LoopAttrT>(A); };
369368
const auto *FirstItr = std::find_if(Attrs.begin(), Attrs.end(), FindFunc);
370369

371370
if (FirstItr == Attrs.end()) // no attributes found
@@ -375,16 +374,16 @@ static void CheckForDuplicateCodeAlignAttrs(Sema &S,
375374
std::optional<llvm::APSInt> FirstValue;
376375

377376
const auto *CAFA =
378-
dyn_cast<ConstantExpr>(cast<CodeAlignAttr>(*FirstItr)->getAlignment());
377+
dyn_cast<ConstantExpr>(cast<LoopAttrT>(*FirstItr)->getAlignment());
379378
// Return early if first alignment expression is dependent (since we don't
380379
// know what the effective size will be), and skip the loop entirely.
381380
if (!CAFA)
382381
return;
383382

384383
while (Attrs.end() != (LastFoundItr = std::find_if(LastFoundItr + 1,
385384
Attrs.end(), FindFunc))) {
386-
const auto *CASA = dyn_cast<ConstantExpr>(
387-
cast<CodeAlignAttr>(*LastFoundItr)->getAlignment());
385+
const auto *CASA =
386+
dyn_cast<ConstantExpr>(cast<LoopAttrT>(*LastFoundItr)->getAlignment());
388387
// If the value is dependent, we can not test anything.
389388
if (!CASA)
390389
return;
@@ -635,10 +634,10 @@ void Sema::ProcessStmtAttributes(Stmt *S, const ParsedAttributes &InAttrs,
635634
}
636635

637636
CheckForIncompatibleAttributes(*this, OutAttrs);
638-
CheckForDuplicateCodeAlignAttrs(*this, OutAttrs);
637+
CheckForDuplicateLoopAttrs<CodeAlignAttr>(*this, OutAttrs);
639638
}
640639

641-
bool Sema::CheckRebuiltCodeAlignStmtAttributes(ArrayRef<const Attr *> Attrs) {
642-
CheckForDuplicateCodeAlignAttrs(*this, Attrs);
640+
bool Sema::CheckRebuiltStmtAttributes(ArrayRef<const Attr *> Attrs) {
641+
CheckForDuplicateLoopAttrs<CodeAlignAttr>(*this, Attrs);
643642
return false;
644643
}

clang/lib/Sema/TreeTransform.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,7 @@ class TreeTransform {
13781378
StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
13791379
ArrayRef<const Attr *> Attrs,
13801380
Stmt *SubStmt) {
1381-
if (SemaRef.CheckRebuiltCodeAlignStmtAttributes(Attrs))
1381+
if (SemaRef.CheckRebuiltStmtAttributes(Attrs))
13821382
return StmtError();
13831383
return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
13841384
}

0 commit comments

Comments
 (0)