@@ -1620,6 +1620,34 @@ static bool isTargetVariantEnvironment(const TargetInfo &TI,
16201620 return false ;
16211621}
16221622
1623+ static bool IsBuiltinTrait (Token &Tok) {
1624+
1625+ #define TYPE_TRAIT_1 (Spelling, Name, Key ) \
1626+ case tok::kw_##Spelling: \
1627+ return true ;
1628+ #define TYPE_TRAIT_2 (Spelling, Name, Key ) \
1629+ case tok::kw_##Spelling: \
1630+ return true ;
1631+ #define TYPE_TRAIT_N (Spelling, Name, Key ) \
1632+ case tok::kw_##Spelling: \
1633+ return true ;
1634+ #define ARRAY_TYPE_TRAIT (Spelling, Name, Key ) \
1635+ case tok::kw_##Spelling: \
1636+ return true ;
1637+ #define EXPRESSION_TRAIT (Spelling, Name, Key ) \
1638+ case tok::kw_##Spelling: \
1639+ return true ;
1640+ #define TRANSFORM_TYPE_TRAIT_DEF (K, Spelling ) \
1641+ case tok::kw___##Spelling: \
1642+ return true ;
1643+
1644+ switch (Tok.getKind ()) {
1645+ default :
1646+ return false ;
1647+ #include " clang/Basic/TokenKinds.def"
1648+ }
1649+ }
1650+
16231651// / ExpandBuiltinMacro - If an identifier token is read that is to be expanded
16241652// / as a builtin macro, handle it and return the next token as 'Tok'.
16251653void Preprocessor::ExpandBuiltinMacro (Token &Tok) {
@@ -1832,25 +1860,11 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
18321860 getTargetInfo ().getTargetOpts ().FeatureMap );
18331861 }
18341862 return true ;
1835- } else if (II->getTokenID () != tok::identifier ||
1836- II->hasRevertedTokenIDToIdentifier ()) {
1837- // Treat all keywords that introduce a custom syntax of the form
1838- //
1839- // '__some_keyword' '(' [...] ')'
1840- //
1841- // as being "builtin functions", even if the syntax isn't a valid
1842- // function call (for example, because the builtin takes a type
1843- // argument).
1844- if (II->getName ().starts_with (" __builtin_" ) ||
1845- II->getName ().starts_with (" __is_" ) ||
1846- II->getName ().starts_with (" __has_" ))
1847- return true ;
1848- return llvm::StringSwitch<bool >(II->getName ())
1849- .Case (" __array_rank" , true )
1850- .Case (" __array_extent" , true )
1851- #define TRANSFORM_TYPE_TRAIT_DEF (_, Trait ) .Case(" __" #Trait, true )
1852- #include " clang/Basic/TransformTypeTraits.def"
1853- .Default (false );
1863+ } else if (IsBuiltinTrait (Tok)) {
1864+ return true ;
1865+ } else if (II->getTokenID () != tok::identifier &&
1866+ II->getName ().starts_with (" __builtin_" )) {
1867+ return true ;
18541868 } else {
18551869 return llvm::StringSwitch<bool >(II->getName ())
18561870 // Report builtin templates as being builtins.
0 commit comments