@@ -1293,7 +1293,7 @@ static bool EvaluateHasIncludeNext(Token &Tok,
1293
1293
// / integer values.
1294
1294
static void EvaluateFeatureLikeBuiltinMacro (llvm::raw_svector_ostream& OS,
1295
1295
Token &Tok, IdentifierInfo *II,
1296
- Preprocessor &PP,
1296
+ Preprocessor &PP, bool ExpandArgs,
1297
1297
llvm::function_ref<
1298
1298
int (Token &Tok,
1299
1299
bool &HasLexedNextTok)> Op) {
@@ -1319,7 +1319,10 @@ static void EvaluateFeatureLikeBuiltinMacro(llvm::raw_svector_ostream& OS,
1319
1319
bool SuppressDiagnostic = false ;
1320
1320
while (true ) {
1321
1321
// Parse next token.
1322
- PP.LexUnexpandedToken (Tok);
1322
+ if (ExpandArgs)
1323
+ PP.Lex (Tok);
1324
+ else
1325
+ PP.LexUnexpandedToken (Tok);
1323
1326
1324
1327
already_lexed:
1325
1328
switch (Tok.getKind ()) {
@@ -1609,21 +1612,21 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
1609
1612
OS << CounterValue++;
1610
1613
Tok.setKind (tok::numeric_constant);
1611
1614
} else if (II == Ident__has_feature) {
1612
- EvaluateFeatureLikeBuiltinMacro (OS, Tok, II, *this ,
1615
+ EvaluateFeatureLikeBuiltinMacro (OS, Tok, II, *this , false ,
1613
1616
[this ](Token &Tok, bool &HasLexedNextToken) -> int {
1614
1617
IdentifierInfo *II = ExpectFeatureIdentifierInfo (Tok, *this ,
1615
1618
diag::err_feature_check_malformed);
1616
1619
return II && HasFeature (*this , II->getName ());
1617
1620
});
1618
1621
} else if (II == Ident__has_extension) {
1619
- EvaluateFeatureLikeBuiltinMacro (OS, Tok, II, *this ,
1622
+ EvaluateFeatureLikeBuiltinMacro (OS, Tok, II, *this , false ,
1620
1623
[this ](Token &Tok, bool &HasLexedNextToken) -> int {
1621
1624
IdentifierInfo *II = ExpectFeatureIdentifierInfo (Tok, *this ,
1622
1625
diag::err_feature_check_malformed);
1623
1626
return II && HasExtension (*this , II->getName ());
1624
1627
});
1625
1628
} else if (II == Ident__has_builtin) {
1626
- EvaluateFeatureLikeBuiltinMacro (OS, Tok, II, *this ,
1629
+ EvaluateFeatureLikeBuiltinMacro (OS, Tok, II, *this , false ,
1627
1630
[this ](Token &Tok, bool &HasLexedNextToken) -> int {
1628
1631
IdentifierInfo *II = ExpectFeatureIdentifierInfo (Tok, *this ,
1629
1632
diag::err_feature_check_malformed);
@@ -1675,20 +1678,20 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
1675
1678
}
1676
1679
});
1677
1680
} else if (II == Ident__is_identifier) {
1678
- EvaluateFeatureLikeBuiltinMacro (OS, Tok, II, *this ,
1681
+ EvaluateFeatureLikeBuiltinMacro (OS, Tok, II, *this , false ,
1679
1682
[](Token &Tok, bool &HasLexedNextToken) -> int {
1680
1683
return Tok.is (tok::identifier);
1681
1684
});
1682
1685
} else if (II == Ident__has_attribute) {
1683
- EvaluateFeatureLikeBuiltinMacro (OS, Tok, II, *this ,
1686
+ EvaluateFeatureLikeBuiltinMacro (OS, Tok, II, *this , true ,
1684
1687
[this ](Token &Tok, bool &HasLexedNextToken) -> int {
1685
1688
IdentifierInfo *II = ExpectFeatureIdentifierInfo (Tok, *this ,
1686
1689
diag::err_feature_check_malformed);
1687
1690
return II ? hasAttribute (AttrSyntax::GNU, nullptr , II,
1688
1691
getTargetInfo (), getLangOpts ()) : 0 ;
1689
1692
});
1690
1693
} else if (II == Ident__has_declspec) {
1691
- EvaluateFeatureLikeBuiltinMacro (OS, Tok, II, *this ,
1694
+ EvaluateFeatureLikeBuiltinMacro (OS, Tok, II, *this , true ,
1692
1695
[this ](Token &Tok, bool &HasLexedNextToken) -> int {
1693
1696
IdentifierInfo *II = ExpectFeatureIdentifierInfo (Tok, *this ,
1694
1697
diag::err_feature_check_malformed);
@@ -1704,8 +1707,8 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
1704
1707
} else if (II == Ident__has_cpp_attribute ||
1705
1708
II == Ident__has_c_attribute) {
1706
1709
bool IsCXX = II == Ident__has_cpp_attribute;
1707
- EvaluateFeatureLikeBuiltinMacro (
1708
- OS, Tok, II, * this , [&](Token &Tok, bool &HasLexedNextToken) -> int {
1710
+ EvaluateFeatureLikeBuiltinMacro (OS, Tok, II, * this , true ,
1711
+ [&](Token &Tok, bool &HasLexedNextToken) -> int {
1709
1712
IdentifierInfo *ScopeII = nullptr ;
1710
1713
IdentifierInfo *II = ExpectFeatureIdentifierInfo (
1711
1714
Tok, *this , diag::err_feature_check_malformed);
@@ -1719,7 +1722,8 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
1719
1722
HasLexedNextToken = true ;
1720
1723
else {
1721
1724
ScopeII = II;
1722
- LexUnexpandedToken (Tok);
1725
+ // Lex an expanded token for the attribute name.
1726
+ Lex (Tok);
1723
1727
II = ExpectFeatureIdentifierInfo (Tok, *this ,
1724
1728
diag::err_feature_check_malformed);
1725
1729
}
@@ -1746,7 +1750,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
1746
1750
Tok.setKind (tok::numeric_constant);
1747
1751
} else if (II == Ident__has_warning) {
1748
1752
// The argument should be a parenthesized string literal.
1749
- EvaluateFeatureLikeBuiltinMacro (OS, Tok, II, *this ,
1753
+ EvaluateFeatureLikeBuiltinMacro (OS, Tok, II, *this , false ,
1750
1754
[this ](Token &Tok, bool &HasLexedNextToken) -> int {
1751
1755
std::string WarningName;
1752
1756
SourceLocation StrStartLoc = Tok.getLocation ();
@@ -1777,7 +1781,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
1777
1781
// The argument to this builtin should be an identifier. The
1778
1782
// builtin evaluates to 1 when that identifier names the module we are
1779
1783
// currently building.
1780
- EvaluateFeatureLikeBuiltinMacro (OS, Tok, II, *this ,
1784
+ EvaluateFeatureLikeBuiltinMacro (OS, Tok, II, *this , false ,
1781
1785
[this ](Token &Tok, bool &HasLexedNextToken) -> int {
1782
1786
IdentifierInfo *II = ExpectFeatureIdentifierInfo (Tok, *this ,
1783
1787
diag::err_expected_id_building_module);
@@ -1837,28 +1841,32 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
1837
1841
return ;
1838
1842
} else if (II == Ident__is_target_arch) {
1839
1843
EvaluateFeatureLikeBuiltinMacro (
1840
- OS, Tok, II, *this , [this ](Token &Tok, bool &HasLexedNextToken) -> int {
1844
+ OS, Tok, II, *this , false ,
1845
+ [this ](Token &Tok, bool &HasLexedNextToken) -> int {
1841
1846
IdentifierInfo *II = ExpectFeatureIdentifierInfo (
1842
1847
Tok, *this , diag::err_feature_check_malformed);
1843
1848
return II && isTargetArch (getTargetInfo (), II);
1844
1849
});
1845
1850
} else if (II == Ident__is_target_vendor) {
1846
1851
EvaluateFeatureLikeBuiltinMacro (
1847
- OS, Tok, II, *this , [this ](Token &Tok, bool &HasLexedNextToken) -> int {
1852
+ OS, Tok, II, *this , false ,
1853
+ [this ](Token &Tok, bool &HasLexedNextToken) -> int {
1848
1854
IdentifierInfo *II = ExpectFeatureIdentifierInfo (
1849
1855
Tok, *this , diag::err_feature_check_malformed);
1850
1856
return II && isTargetVendor (getTargetInfo (), II);
1851
1857
});
1852
1858
} else if (II == Ident__is_target_os) {
1853
1859
EvaluateFeatureLikeBuiltinMacro (
1854
- OS, Tok, II, *this , [this ](Token &Tok, bool &HasLexedNextToken) -> int {
1860
+ OS, Tok, II, *this , false ,
1861
+ [this ](Token &Tok, bool &HasLexedNextToken) -> int {
1855
1862
IdentifierInfo *II = ExpectFeatureIdentifierInfo (
1856
1863
Tok, *this , diag::err_feature_check_malformed);
1857
1864
return II && isTargetOS (getTargetInfo (), II);
1858
1865
});
1859
1866
} else if (II == Ident__is_target_environment) {
1860
1867
EvaluateFeatureLikeBuiltinMacro (
1861
- OS, Tok, II, *this , [this ](Token &Tok, bool &HasLexedNextToken) -> int {
1868
+ OS, Tok, II, *this , false ,
1869
+ [this ](Token &Tok, bool &HasLexedNextToken) -> int {
1862
1870
IdentifierInfo *II = ExpectFeatureIdentifierInfo (
1863
1871
Tok, *this , diag::err_feature_check_malformed);
1864
1872
return II && isTargetEnvironment (getTargetInfo (), II);
0 commit comments