Skip to content

Commit

Permalink
[NFC][CLANG] Rename duplicate loop attributes diagnostic functions (#…
Browse files Browse the repository at this point in the history
…75657)

This patch renames CheckForDuplicateCodeAlignAttrs() to
CheckForDuplicateLoopAttrs() and corresponding other functions that call
it to be used for other statement attributes in future.
  • Loading branch information
smanna12 committed Dec 16, 2023
1 parent 5545b25 commit 7a0fd97
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -2102,7 +2102,7 @@ class Sema final {
SourceLocation AttrLoc);

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

bool CheckQualifiedFunctionForTypeId(QualType T, SourceLocation Loc);

Expand Down
21 changes: 10 additions & 11 deletions clang/lib/Sema/SemaStmtAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,11 +361,10 @@ static Attr *handleCodeAlignAttr(Sema &S, Stmt *St, const ParsedAttr &A) {
}

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

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

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

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

CheckForIncompatibleAttributes(*this, OutAttrs);
CheckForDuplicateCodeAlignAttrs(*this, OutAttrs);
CheckForDuplicateLoopAttrs<CodeAlignAttr>(*this, OutAttrs);
}

bool Sema::CheckRebuiltCodeAlignStmtAttributes(ArrayRef<const Attr *> Attrs) {
CheckForDuplicateCodeAlignAttrs(*this, Attrs);
bool Sema::CheckRebuiltStmtAttributes(ArrayRef<const Attr *> Attrs) {
CheckForDuplicateLoopAttrs<CodeAlignAttr>(*this, Attrs);
return false;
}
2 changes: 1 addition & 1 deletion clang/lib/Sema/TreeTransform.h
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ class TreeTransform {
StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
ArrayRef<const Attr *> Attrs,
Stmt *SubStmt) {
if (SemaRef.CheckRebuiltCodeAlignStmtAttributes(Attrs))
if (SemaRef.CheckRebuiltStmtAttributes(Attrs))
return StmtError();
return SemaRef.BuildAttributedStmt(AttrLoc, Attrs, SubStmt);
}
Expand Down

0 comments on commit 7a0fd97

Please sign in to comment.