[cfe-commits] r55639 - in /cfe/trunk: lib/Lex/Preprocessor.cpp test/Preprocessor/extension-warning.c

Steve Naroff snaroff at apple.com
Tue Sep 2 11:50:17 PDT 2008


Author: snaroff
Date: Tue Sep  2 13:50:17 2008
New Revision: 55639

URL: http://llvm.org/viewvc/llvm-project?rev=55639&view=rev
Log:
- Implement __block.
- Replace FIXME in Preprocessor::HandleIdentifier() with a check that avoids diagnosing extension tokens that originate from macro definitions.

Added:
    cfe/trunk/test/Preprocessor/extension-warning.c
Modified:
    cfe/trunk/lib/Lex/Preprocessor.cpp

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=55639&r1=55638&r2=55639&view=diff

==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Tue Sep  2 13:50:17 2008
@@ -476,6 +476,14 @@
     DefineBuiltinMacro(Buf, "__int64=long long");
     DefineBuiltinMacro(Buf, "__declspec(X)=");
   }
+  // Directly modeled after the attribute-based implementation in GCC. 
+  if (PP.getLangOptions().Blocks)
+     DefineBuiltinMacro(Buf, "__block=__attribute__((__blocks__(byref)))");
+  else
+    // This allows "__block int unusedVar;" even when blocks are disabled.
+    // This is modeled after GCC's handling of __strong/__weak.
+    DefineBuiltinMacro(Buf, "__block=");
+
   // FIXME: Should emit a #line directive here.
 }
 
@@ -594,8 +602,7 @@
   Identifier.setKind(II.getTokenID());
     
   // If this is an extension token, diagnose its use.
-  // FIXME: tried (unsuccesfully) to shut this up when compiling with gnu99
-  // For now, I'm just commenting it out (while I work on attributes).
-  if (II.isExtensionToken() && Features.C99) 
+  // We avoid diagnosing tokens that originate from macro definitions.
+  if (II.isExtensionToken() && Features.C99 && !DisableMacroExpansion)
     Diag(Identifier, diag::ext_token_used);
 }

Added: cfe/trunk/test/Preprocessor/extension-warning.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/extension-warning.c?rev=55639&view=auto

==============================================================================
--- cfe/trunk/test/Preprocessor/extension-warning.c (added)
+++ cfe/trunk/test/Preprocessor/extension-warning.c Tue Sep  2 13:50:17 2008
@@ -0,0 +1,10 @@
+// RUN: clang -fsyntax-only -verify -pedantic %s
+
+// The preprocessor shouldn't warn about extensions within macro bodies that
+// aren't expanded.
+#define __block __attribute__((__blocks__(byref)))
+
+// This warning is entirely valid.
+__block int x; // expected-warning{{extension used}}
+
+void whatever() {}





More information about the cfe-commits mailing list