@@ -1535,13 +1535,12 @@ bool SemaARM::areLaxCompatibleSveTypes(QualType FirstType,
15351535 IsLaxCompatible (SecondType, FirstType);
15361536}
15371537
1538- enum FirstParam { Unsupported, Duplicate, Unknown };
1539- enum SecondParam { None, CPU, Tune };
1540- enum ThirdParam { Target, TargetClones, TargetVersion } ;
1538+ bool SemaARM::checkTargetVersionAttr ( const StringRef Param,
1539+ const SourceLocation Loc) {
1540+ using namespace DiagAttrParams ;
15411541
1542- bool SemaARM::checkTargetVersionAttr (StringRef Str, SourceLocation Loc) {
15431542 llvm::SmallVector<StringRef, 8 > Features;
1544- Str .split (Features, ' +' );
1543+ Param .split (Features, ' +' );
15451544 for (StringRef Feat : Features) {
15461545 Feat = Feat.trim ();
15471546 if (Feat == " default" )
@@ -1553,30 +1552,32 @@ bool SemaARM::checkTargetVersionAttr(StringRef Str, SourceLocation Loc) {
15531552 return false ;
15541553}
15551554
1556- bool SemaARM::checkTargetClonesAttr (SmallVectorImpl<StringRef> &Strs,
1557- SmallVectorImpl<SourceLocation> &Locs,
1558- SmallVectorImpl<SmallString<64 >> &Buffer) {
1555+ bool SemaARM::checkTargetClonesAttr (
1556+ SmallVectorImpl<StringRef> &Params, SmallVectorImpl<SourceLocation> &Locs,
1557+ SmallVectorImpl<SmallString<64 >> &NewParams) {
1558+ using namespace DiagAttrParams ;
1559+
15591560 if (!getASTContext ().getTargetInfo ().hasFeature (" fmv" ))
15601561 return true ;
15611562
1562- assert (Strs .size () == Locs.size () &&
1563- " Mismatch between number of strings and locations" );
1563+ assert (Params .size () == Locs.size () &&
1564+ " Mismatch between number of string parameters and locations" );
15641565
15651566 bool HasDefault = false ;
15661567 bool HasNonDefault = false ;
1567- for (unsigned I = 0 ; I < Strs .size (); ++I) {
1568- StringRef Str = Strs [I].trim ();
1569- SourceLocation Loc = Locs[I];
1568+ for (unsigned I = 0 , E = Params .size (); I < E ; ++I) {
1569+ const StringRef Param = Params [I].trim ();
1570+ const SourceLocation & Loc = Locs[I];
15701571
1571- if (Str .empty ())
1572+ if (Param .empty ())
15721573 return Diag (Loc, diag::warn_unsupported_target_attribute)
15731574 << Unsupported << None << " " << TargetClones;
15741575
1575- if (Str == " default" ) {
1576+ if (Param == " default" ) {
15761577 if (HasDefault)
15771578 Diag (Loc, diag::warn_target_clone_duplicate_options);
15781579 else {
1579- Buffer .push_back (Str );
1580+ NewParams .push_back (Param );
15801581 HasDefault = true ;
15811582 }
15821583 continue ;
@@ -1585,7 +1586,7 @@ bool SemaARM::checkTargetClonesAttr(SmallVectorImpl<StringRef> &Strs,
15851586 bool HasCodeGenImpact = false ;
15861587 llvm::SmallVector<StringRef, 8 > Features;
15871588 llvm::SmallVector<StringRef, 8 > ValidFeatures;
1588- Str .split (Features, ' +' );
1589+ Param .split (Features, ' +' );
15891590 for (StringRef Feat : Features) {
15901591 Feat = Feat.trim ();
15911592 if (!getASTContext ().getTargetInfo ().validateCpuSupports (Feat)) {
@@ -1597,24 +1598,27 @@ bool SemaARM::checkTargetClonesAttr(SmallVectorImpl<StringRef> &Strs,
15971598 HasCodeGenImpact = true ;
15981599 ValidFeatures.push_back (Feat);
15991600 }
1600- // Canonize TargetClones Attributes
1601- SmallString<64 > NewStr;
1602- llvm::sort (ValidFeatures);
1603- for (StringRef Feat : ValidFeatures) {
1604- if (!NewStr.empty ())
1605- NewStr.append (" +" );
1606- NewStr.append (Feat);
1601+
1602+ // Ignore features that don't impact code generation.
1603+ if (!HasCodeGenImpact) {
1604+ Diag (Loc, diag::warn_target_clone_no_impact_options);
1605+ continue ;
16071606 }
1608- if (llvm::is_contained (Buffer, NewStr))
1607+
1608+ if (ValidFeatures.empty ())
1609+ continue ;
1610+
1611+ // Canonicalize attribute parameter.
1612+ llvm::sort (ValidFeatures);
1613+ SmallString<64 > NewParam (llvm::join (ValidFeatures, " +" ));
1614+ if (llvm::is_contained (NewParams, NewParam)) {
16091615 Diag (Loc, diag::warn_target_clone_duplicate_options);
1610- else if (!HasCodeGenImpact)
1611- // Ignore features in target_clone attribute that don't impact
1612- // code generation
1613- Diag (Loc, diag::warn_target_clone_no_impact_options);
1614- else if (!NewStr.empty ()) {
1615- Buffer.push_back (NewStr);
1616- HasNonDefault = true ;
1616+ continue ;
16171617 }
1618+
1619+ // Valid non-default argument.
1620+ NewParams.push_back (NewParam);
1621+ HasNonDefault = true ;
16181622 }
16191623 if (!HasNonDefault)
16201624 return true ;
0 commit comments