c: small refactoring of checking for __attribute__(const))

per Richard's comment.

llvm-svn: 161786
This commit is contained in:
Fariborz Jahanian 2012-08-13 21:15:02 +00:00
parent 209bd65ea4
commit 7513fa346c
4 changed files with 11 additions and 12 deletions

View File

@ -1054,7 +1054,7 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
if (Tok.is(tok::l_paren)) {
// Read the identifier
Lex(Tok);
if (Tok.is(tok::identifier)) {
if (Tok.is(tok::identifier) || Tok.is(tok::kw_const)) {
FeatureII = Tok.getIdentifierInfo();
// Read the ')'.
@ -1062,13 +1062,6 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
if (Tok.is(tok::r_paren))
IsValid = true;
}
else if (Tok.is(tok::kw_const)) {
FeatureII = getIdentifierInfo("const");
// Read the ')'.
Lex(Tok);
if (Tok.is(tok::r_paren))
IsValid = true;
}
}
bool Value = false;

View File

@ -24,3 +24,13 @@ int has_has_attribute();
#if !__has_attribute(something_we_dont_have)
int has_something_we_dont_have();
#endif
// rdar://10253857
#if __has_attribute(__const)
int fn3() __attribute__ ((__const));
#endif
#if __has_attribute(const)
static int constFunction() __attribute__((const));
#endif

View File

@ -34,9 +34,7 @@ extern inline int useStaticInlineFromExtern () {
return useStaticFromStatic(); // no-warning
}
#if __has_attribute(const)
static int constFunction() __attribute__((const));
#endif
inline int useConst () {
return constFunction(); // no-warning

View File

@ -82,9 +82,7 @@ void t5() {
int fn1() __attribute__ ((warn_unused_result));
int fn2() __attribute__ ((pure));
#if __has_attribute(__const)
int fn3() __attribute__ ((__const));
#endif
// rdar://6587766
int t6() {
if (fn1() < 0 || fn2(2,1) < 0 || fn3(2) < 0) // no warnings