[cfe-commits] r161786 - in /cfe/trunk: lib/Lex/PPMacroExpansion.cpp test/Preprocessor/has_attribute.c test/Sema/inline.c test/Sema/unused-expr.c

Fariborz Jahanian fjahanian at apple.com
Mon Aug 13 14:15:02 PDT 2012


Author: fjahanian
Date: Mon Aug 13 16:15:02 2012
New Revision: 161786

URL: http://llvm.org/viewvc/llvm-project?rev=161786&view=rev
Log:
c: small refactoring of checking for __attribute__(const))
per Richard's comment.

Modified:
    cfe/trunk/lib/Lex/PPMacroExpansion.cpp
    cfe/trunk/test/Preprocessor/has_attribute.c
    cfe/trunk/test/Sema/inline.c
    cfe/trunk/test/Sema/unused-expr.c

Modified: cfe/trunk/lib/Lex/PPMacroExpansion.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPMacroExpansion.cpp?rev=161786&r1=161785&r2=161786&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPMacroExpansion.cpp (original)
+++ cfe/trunk/lib/Lex/PPMacroExpansion.cpp Mon Aug 13 16:15:02 2012
@@ -1054,7 +1054,7 @@
     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 @@
         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;

Modified: cfe/trunk/test/Preprocessor/has_attribute.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/has_attribute.c?rev=161786&r1=161785&r2=161786&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/has_attribute.c (original)
+++ cfe/trunk/test/Preprocessor/has_attribute.c Mon Aug 13 16:15:02 2012
@@ -24,3 +24,13 @@
 #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
+

Modified: cfe/trunk/test/Sema/inline.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/inline.c?rev=161786&r1=161785&r2=161786&view=diff
==============================================================================
--- cfe/trunk/test/Sema/inline.c (original)
+++ cfe/trunk/test/Sema/inline.c Mon Aug 13 16:15:02 2012
@@ -34,9 +34,7 @@
   return useStaticFromStatic(); // no-warning
 }
 
-#if __has_attribute(const)
 static int constFunction() __attribute__((const));
-#endif
 
 inline int useConst () {
   return constFunction(); // no-warning

Modified: cfe/trunk/test/Sema/unused-expr.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/unused-expr.c?rev=161786&r1=161785&r2=161786&view=diff
==============================================================================
--- cfe/trunk/test/Sema/unused-expr.c (original)
+++ cfe/trunk/test/Sema/unused-expr.c Mon Aug 13 16:15:02 2012
@@ -82,9 +82,7 @@
 
 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





More information about the cfe-commits mailing list