[cfe-commits] r80094 - in /cfe/trunk: include/clang/Basic/Diagnostic.h include/clang/Parse/DeclSpec.h lib/Parse/ParseDecl.cpp test/Sema/implicit-int.c

Douglas Gregor dgregor at apple.com
Wed Aug 26 07:27:30 PDT 2009


Author: dgregor
Date: Wed Aug 26 09:27:30 2009
New Revision: 80094

URL: http://llvm.org/viewvc/llvm-project?rev=80094&view=rev
Log:
Fix bug in __extension__ handling for declarations, from Abramo
Bagnara with a fix from Enea Zaffanella!

Modified:
    cfe/trunk/include/clang/Basic/Diagnostic.h
    cfe/trunk/include/clang/Parse/DeclSpec.h
    cfe/trunk/lib/Parse/ParseDecl.cpp
    cfe/trunk/test/Sema/implicit-int.c

Modified: cfe/trunk/include/clang/Basic/Diagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Diagnostic.h?rev=80094&r1=80093&r2=80094&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/Diagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/Diagnostic.h Wed Aug 26 09:27:30 2009
@@ -256,6 +256,7 @@
   /// entirely silenced, no matter how they are mapped.
   void IncrementAllExtensionsSilenced() { ++AllExtensionsSilenced; }
   void DecrementAllExtensionsSilenced() { --AllExtensionsSilenced; }
+  bool hasAllExtensionsSilenced() { return AllExtensionsSilenced != 0; }
   
   /// setDiagnosticMapping - This allows the client to specify that certain
   /// warnings are ignored.  Notes can never be mapped, errors can only be

Modified: cfe/trunk/include/clang/Parse/DeclSpec.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/DeclSpec.h?rev=80094&r1=80093&r2=80094&view=diff

==============================================================================
--- cfe/trunk/include/clang/Parse/DeclSpec.h (original)
+++ cfe/trunk/include/clang/Parse/DeclSpec.h Wed Aug 26 09:27:30 2009
@@ -853,6 +853,9 @@
   DeclaratorChunk::ParamInfo InlineParams[16];
   bool InlineParamsUsed;
 
+  /// Extension - true if the declaration is preceded by __extension__.
+  bool Extension : 1;
+
   friend struct DeclaratorChunk;
 
 public:
@@ -861,7 +864,7 @@
       Kind(DK_Abstract),
       InvalidType(DS.getTypeSpecType() == DeclSpec::TST_error),
       GroupingParens(false), AttrList(0), AsmLabel(0), Type(0),
-      InlineParamsUsed(false) {
+      InlineParamsUsed(false), Extension(false) {
   }
   
   ~Declarator() {
@@ -1090,6 +1093,9 @@
   void setAsmLabel(ActionBase::ExprTy *E) { AsmLabel = E; }
   ActionBase::ExprTy *getAsmLabel() const { return AsmLabel; }
 
+  void setExtension(bool Val = true) { Extension = Val; }
+  bool getExtension() const { return Extension; }
+
   ActionBase::TypeTy *getDeclaratorIdType() const { return Type; }
 
   OverloadedOperatorKind getOverloadedOperator() const { return OperatorKind; }

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=80094&r1=80093&r2=80094&view=diff

==============================================================================
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Wed Aug 26 09:27:30 2009
@@ -1509,10 +1509,19 @@
       // Convert them all to fields.
       for (unsigned i = 0, e = FieldDeclarators.size(); i != e; ++i) {
         FieldDeclarator &FD = FieldDeclarators[i];
+        DeclPtrTy Field;
         // Install the declarator into the current TagDecl.
-        DeclPtrTy Field = Actions.ActOnField(CurScope, TagDecl,
-                                             DS.getSourceRange().getBegin(),
-                                             FD.D, FD.BitfieldSize);
+        if (FD.D.getExtension()) {
+          // Silences extension warnings
+          ExtensionRAIIObject O(Diags);
+          Field = Actions.ActOnField(CurScope, TagDecl,
+                                     DS.getSourceRange().getBegin(),
+                                     FD.D, FD.BitfieldSize);
+        } else {
+          Field = Actions.ActOnField(CurScope, TagDecl,
+                                     DS.getSourceRange().getBegin(),
+                                     FD.D, FD.BitfieldSize);
+        }
         FieldDecls.push_back(Field);
       }
     } else { // Handle @defs
@@ -2016,6 +2025,8 @@
 void Parser::ParseDeclaratorInternal(Declarator &D,
                                      DirectDeclParseFunction DirectDeclParser) {
 
+  if (Diags.hasAllExtensionsSilenced())
+    D.setExtension();
   // C++ member pointers start with a '::' or a nested-name.
   // Member pointers get special handling, since there's no place for the
   // scope spec in the generic path below.

Modified: cfe/trunk/test/Sema/implicit-int.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/implicit-int.c?rev=80094&r1=80093&r2=80094&view=diff

==============================================================================
--- cfe/trunk/test/Sema/implicit-int.c (original)
+++ cfe/trunk/test/Sema/implicit-int.c Wed Aug 26 09:27:30 2009
@@ -24,7 +24,7 @@
 }
 
 struct foo {
- __extension__ __attribute__((packed)) x : 4; // expected-warning {{type specifier missing, defaults to 'int'}}
+ __extension__ __attribute__((packed)) x : 4;
 };
 
 





More information about the cfe-commits mailing list