@@ -1602,6 +1602,34 @@ static bool isTargetVariantEnvironment(const TargetInfo &TI,
1602
1602
return false ;
1603
1603
}
1604
1604
1605
+ static bool IsBuiltinTrait (Token &Tok) {
1606
+
1607
+ #define TYPE_TRAIT_1 (Spelling, Name, Key ) \
1608
+ case tok::kw_##Spelling: \
1609
+ return true ;
1610
+ #define TYPE_TRAIT_2 (Spelling, Name, Key ) \
1611
+ case tok::kw_##Spelling: \
1612
+ return true ;
1613
+ #define TYPE_TRAIT_N (Spelling, Name, Key ) \
1614
+ case tok::kw_##Spelling: \
1615
+ return true ;
1616
+ #define ARRAY_TYPE_TRAIT (Spelling, Name, Key ) \
1617
+ case tok::kw_##Spelling: \
1618
+ return true ;
1619
+ #define EXPRESSION_TRAIT (Spelling, Name, Key ) \
1620
+ case tok::kw_##Spelling: \
1621
+ return true ;
1622
+ #define TRANSFORM_TYPE_TRAIT_DEF (K, Spelling ) \
1623
+ case tok::kw___##Spelling: \
1624
+ return true ;
1625
+
1626
+ switch (Tok.getKind ()) {
1627
+ default :
1628
+ return false ;
1629
+ #include " clang/Basic/TokenKinds.def"
1630
+ }
1631
+ }
1632
+
1605
1633
// / ExpandBuiltinMacro - If an identifier token is read that is to be expanded
1606
1634
// / as a builtin macro, handle it and return the next token as 'Tok'.
1607
1635
void Preprocessor::ExpandBuiltinMacro (Token &Tok) {
@@ -1798,25 +1826,11 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
1798
1826
getTargetInfo ().getTargetOpts ().FeatureMap );
1799
1827
}
1800
1828
return true ;
1801
- } else if (II->getTokenID () != tok::identifier ||
1802
- II->hasRevertedTokenIDToIdentifier ()) {
1803
- // Treat all keywords that introduce a custom syntax of the form
1804
- //
1805
- // '__some_keyword' '(' [...] ')'
1806
- //
1807
- // as being "builtin functions", even if the syntax isn't a valid
1808
- // function call (for example, because the builtin takes a type
1809
- // argument).
1810
- if (II->getName ().starts_with (" __builtin_" ) ||
1811
- II->getName ().starts_with (" __is_" ) ||
1812
- II->getName ().starts_with (" __has_" ))
1813
- return true ;
1814
- return llvm::StringSwitch<bool >(II->getName ())
1815
- .Case (" __array_rank" , true )
1816
- .Case (" __array_extent" , true )
1817
- #define TRANSFORM_TYPE_TRAIT_DEF (_, Trait ) .Case(" __" #Trait, true )
1818
- #include " clang/Basic/TransformTypeTraits.def"
1819
- .Default (false );
1829
+ } else if (IsBuiltinTrait (Tok)) {
1830
+ return true ;
1831
+ } else if (II->getTokenID () != tok::identifier &&
1832
+ II->getName ().starts_with (" __builtin_" )) {
1833
+ return true ;
1820
1834
} else {
1821
1835
return llvm::StringSwitch<bool >(II->getName ())
1822
1836
// Report builtin templates as being builtins.
0 commit comments