@@ -361,11 +361,10 @@ static Attr *handleCodeAlignAttr(Sema &S, Stmt *St, const ParsedAttr &A) {
361
361
}
362
362
363
363
// 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); };
369
368
const auto *FirstItr = std::find_if (Attrs.begin (), Attrs.end (), FindFunc);
370
369
371
370
if (FirstItr == Attrs.end ()) // no attributes found
@@ -375,16 +374,16 @@ static void CheckForDuplicateCodeAlignAttrs(Sema &S,
375
374
std::optional<llvm::APSInt> FirstValue;
376
375
377
376
const auto *CAFA =
378
- dyn_cast<ConstantExpr>(cast<CodeAlignAttr >(*FirstItr)->getAlignment ());
377
+ dyn_cast<ConstantExpr>(cast<LoopAttrT >(*FirstItr)->getAlignment ());
379
378
// Return early if first alignment expression is dependent (since we don't
380
379
// know what the effective size will be), and skip the loop entirely.
381
380
if (!CAFA)
382
381
return ;
383
382
384
383
while (Attrs.end () != (LastFoundItr = std::find_if (LastFoundItr + 1 ,
385
384
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 ());
388
387
// If the value is dependent, we can not test anything.
389
388
if (!CASA)
390
389
return ;
@@ -635,10 +634,10 @@ void Sema::ProcessStmtAttributes(Stmt *S, const ParsedAttributes &InAttrs,
635
634
}
636
635
637
636
CheckForIncompatibleAttributes (*this , OutAttrs);
638
- CheckForDuplicateCodeAlignAttrs (*this , OutAttrs);
637
+ CheckForDuplicateLoopAttrs<CodeAlignAttr> (*this , OutAttrs);
639
638
}
640
639
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);
643
642
return false ;
644
643
}
0 commit comments