@@ -1579,19 +1579,53 @@ bool SemaARM::areLaxCompatibleSveTypes(QualType FirstType,
15791579 IsLaxCompatible (SecondType, FirstType);
15801580}
15811581
1582+ static void appendFeature (StringRef Feat, SmallString<64 > &Buffer) {
1583+ if (!Buffer.empty ())
1584+ Buffer.append (" +" );
1585+ Buffer.append (Feat);
1586+ }
1587+
1588+ static void convertPriorityString (unsigned Priority,
1589+ SmallString<64 > &NewParam) {
1590+ StringRef PriorityString[8 ] = {" P0" , " P1" , " P2" , " P3" ,
1591+ " P4" , " P5" , " P6" , " P7" };
1592+
1593+ assert (Priority > 0 && Priority < 256 && " priority out of range" );
1594+ // Convert priority=[1-31] -> P0 + ... + P4
1595+ for (unsigned BitPos = 0 ; BitPos < 8 ; ++BitPos)
1596+ if (Priority & (1U << BitPos))
1597+ appendFeature (PriorityString[BitPos], NewParam);
1598+ }
1599+
15821600bool SemaARM::checkTargetVersionAttr (const StringRef Param,
1583- const SourceLocation Loc) {
1601+ const SourceLocation Loc,
1602+ SmallString<64 > &NewParam) {
15841603 using namespace DiagAttrParams ;
15851604
1605+ auto [LHS, RHS] = Param.split (' ;' );
1606+ bool IsDefault = false ;
15861607 llvm::SmallVector<StringRef, 8 > Features;
1587- Param .split (Features, ' +' );
1608+ LHS .split (Features, ' +' );
15881609 for (StringRef Feat : Features) {
15891610 Feat = Feat.trim ();
15901611 if (Feat == " default" )
1591- continue ;
1592- if (!getASTContext ().getTargetInfo ().validateCpuSupports (Feat))
1612+ IsDefault = true ;
1613+ else if (!getASTContext ().getTargetInfo ().validateCpuSupports (Feat))
15931614 return Diag (Loc, diag::warn_unsupported_target_attribute)
15941615 << Unsupported << None << Feat << TargetVersion;
1616+ appendFeature (Feat, NewParam);
1617+ }
1618+
1619+ if (!RHS.empty () && RHS.consume_front (" priority=" )) {
1620+ if (IsDefault)
1621+ Diag (Loc, diag::warn_invalid_default_version_priority);
1622+ else {
1623+ unsigned Digit;
1624+ if (RHS.getAsInteger (0 , Digit) || Digit < 1 || Digit > 255 )
1625+ Diag (Loc, diag::warn_version_priority_out_of_range) << RHS;
1626+ else
1627+ convertPriorityString (Digit, NewParam);
1628+ }
15951629 }
15961630 return false ;
15971631}
@@ -1613,15 +1647,20 @@ bool SemaARM::checkTargetClonesAttr(
16131647 const StringRef Param = Params[I].trim ();
16141648 const SourceLocation &Loc = Locs[I];
16151649
1616- if (Param.empty ())
1650+ auto [LHS, RHS] = Param.split (' ;' );
1651+ bool HasPriority = !RHS.empty () && RHS.consume_front (" priority=" );
1652+
1653+ if (LHS.empty ())
16171654 return Diag (Loc, diag::warn_unsupported_target_attribute)
16181655 << Unsupported << None << " " << TargetClones;
16191656
1620- if (Param == " default" ) {
1657+ if (LHS == " default" ) {
16211658 if (HasDefault)
16221659 Diag (Loc, diag::warn_target_clone_duplicate_options);
16231660 else {
1624- NewParams.push_back (Param);
1661+ if (HasPriority)
1662+ Diag (Loc, diag::warn_invalid_default_version_priority);
1663+ NewParams.push_back (LHS);
16251664 HasDefault = true ;
16261665 }
16271666 continue ;
@@ -1630,7 +1669,7 @@ bool SemaARM::checkTargetClonesAttr(
16301669 bool HasCodeGenImpact = false ;
16311670 llvm::SmallVector<StringRef, 8 > Features;
16321671 llvm::SmallVector<StringRef, 8 > ValidFeatures;
1633- Param .split (Features, ' +' );
1672+ LHS .split (Features, ' +' );
16341673 for (StringRef Feat : Features) {
16351674 Feat = Feat.trim ();
16361675 if (!getASTContext ().getTargetInfo ().validateCpuSupports (Feat)) {
@@ -1660,6 +1699,14 @@ bool SemaARM::checkTargetClonesAttr(
16601699 continue ;
16611700 }
16621701
1702+ if (HasPriority) {
1703+ unsigned Digit;
1704+ if (RHS.getAsInteger (0 , Digit) || Digit < 1 || Digit > 255 )
1705+ Diag (Loc, diag::warn_version_priority_out_of_range) << RHS;
1706+ else
1707+ convertPriorityString (Digit, NewParam);
1708+ }
1709+
16631710 // Valid non-default argument.
16641711 NewParams.push_back (NewParam);
16651712 HasNonDefault = true ;
0 commit comments