[cfe-commits] r69777 - in /cfe/trunk: lib/Sema/Sema.h lib/Sema/SemaType.cpp test/Sema/block-literal.c test/Sema/implicit-int.c

Chris Lattner sabre at nondot.org
Tue Apr 21 22:27:59 PDT 2009


Author: lattner
Date: Wed Apr 22 00:27:59 2009
New Revision: 69777

URL: http://llvm.org/viewvc/llvm-project?rev=69777&view=rev
Log:
change implicit int warnings to point to the identifier, not the 
start of the declspec.  The fixit still goes there, and we underline
the declspec.  This helps when the start of the declspec came from a
macro that expanded from a system header.  For example, we now produce:

t.c:2:8: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
static x;
~~~~~~ ^


Modified:
    cfe/trunk/lib/Sema/Sema.h
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/Sema/block-literal.c
    cfe/trunk/test/Sema/implicit-int.c

Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=69777&r1=69776&r2=69777&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Wed Apr 22 00:27:59 2009
@@ -371,7 +371,7 @@
   // Type Analysis / Processing: SemaType.cpp.
   //
   QualType adjustParameterType(QualType T);
-  QualType ConvertDeclSpecToType(const DeclSpec &DS);
+  QualType ConvertDeclSpecToType(const DeclSpec &DS, SourceLocation DeclLoc);
   void ProcessTypeAttributeList(QualType &Result, const AttributeList *AL);
   QualType BuildPointerType(QualType T, unsigned Quals, 
                             SourceLocation Loc, DeclarationName Entity);

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=69777&r1=69776&r2=69777&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Apr 22 00:27:59 2009
@@ -46,9 +46,11 @@
 /// \brief Convert the specified declspec to the appropriate type
 /// object.
 /// \param DS  the declaration specifiers
+/// \param DeclLoc The location of the declarator identifier or invalid if none.
 /// \returns The type described by the declaration specifiers, or NULL
 /// if there was an error.
-QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS) {
+QualType Sema::ConvertDeclSpecToType(const DeclSpec &DS,
+                                     SourceLocation DeclLoc) {
   // FIXME: Should move the logic from DeclSpec::Finish to here for validity
   // checking.
   QualType Result;
@@ -101,20 +103,29 @@
     if (getLangOptions().ImplicitInt) {
       // In C89 mode, we only warn if there is a completely missing declspec
       // when one is not allowed.
-      if (DS.isEmpty())
-        Diag(DS.getSourceRange().getBegin(), diag::warn_missing_declspec)
+      if (DS.isEmpty()) {
+        if (DeclLoc.isInvalid())
+          DeclLoc = DS.getSourceRange().getBegin();
+        Diag(DeclLoc, diag::warn_missing_declspec)
+          << DS.getSourceRange()
         << CodeModificationHint::CreateInsertion(DS.getSourceRange().getBegin(),
                                                  "int");
+      }
     } else if (!DS.hasTypeSpecifier()) {
       // C99 and C++ require a type specifier.  For example, C99 6.7.2p2 says:
       // "At least one type specifier shall be given in the declaration
       // specifiers in each declaration, and in the specifier-qualifier list in
       // each struct declaration and type name."
       // FIXME: Does Microsoft really have the implicit int extension in C++?
-      unsigned DK = getLangOptions().CPlusPlus && !getLangOptions().Microsoft?
-          diag::err_missing_type_specifier
-        : diag::warn_missing_type_specifier;
-      Diag(DS.getSourceRange().getBegin(), DK);
+      if (DeclLoc.isInvalid())
+        DeclLoc = DS.getSourceRange().getBegin();
+
+      if (getLangOptions().CPlusPlus && !getLangOptions().Microsoft)
+        Diag(DeclLoc, diag::err_missing_type_specifier)
+          << DS.getSourceRange();
+      else
+        Diag(DeclLoc, diag::warn_missing_type_specifier)
+          << DS.getSourceRange();
 
       // FIXME: If we could guarantee that the result would be
       // well-formed, it would be useful to have a code insertion hint
@@ -183,13 +194,18 @@
         // id<protocol-list>
         Result = Context.getObjCQualifiedIdType((ObjCProtocolDecl**)PQ,
                                                 DS.getNumProtocolQualifiers());
-      else if (Result == Context.getObjCClassType())
+      else if (Result == Context.getObjCClassType()) {
+        if (DeclLoc.isInvalid())
+          DeclLoc = DS.getSourceRange().getBegin();
         // Class<protocol-list>
-        Diag(DS.getSourceRange().getBegin(), 
-             diag::err_qualified_class_unsupported) << DS.getSourceRange();
-      else
-        Diag(DS.getSourceRange().getBegin(),
-             diag::err_invalid_protocol_qualifiers) << DS.getSourceRange();
+        Diag(DeclLoc, diag::err_qualified_class_unsupported)
+          << DS.getSourceRange();
+      } else {
+        if (DeclLoc.isInvalid())
+          DeclLoc = DS.getSourceRange().getBegin();
+        Diag(DeclLoc, diag::err_invalid_protocol_qualifiers)
+          << DS.getSourceRange();
+      }
     }
     // TypeQuals handled by caller.
     break;
@@ -592,13 +608,13 @@
   case Declarator::DK_Abstract:
   case Declarator::DK_Normal:
   case Declarator::DK_Operator: {
-    const DeclSpec& DS = D.getDeclSpec();
-    if (OmittedReturnType)
+    const DeclSpec &DS = D.getDeclSpec();
+    if (OmittedReturnType) {
       // We default to a dependent type initially.  Can be modified by
       // the first return statement.
       T = Context.DependentTy;
-    else {
-      T = ConvertDeclSpecToType(DS);
+    } else {
+      T = ConvertDeclSpecToType(DS, D.getIdentifierLoc());
       if (T.isNull())
         return T;
     }

Modified: cfe/trunk/test/Sema/block-literal.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/block-literal.c?rev=69777&r1=69776&r2=69777&view=diff

==============================================================================
--- cfe/trunk/test/Sema/block-literal.c (original)
+++ cfe/trunk/test/Sema/block-literal.c Wed Apr 22 00:27:59 2009
@@ -40,7 +40,7 @@
 
 foo:
 	takeclosure(^{ x = 4; });  // expected-error {{variable is not assignable (missing __block type specifier)}}
-  __block y = 7; 
+  __block y = 7;    // expected-warning {{type specifier missing, defaults to 'int'}}
   takeclosure(^{ y = 8; });
 }
 

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

==============================================================================
--- cfe/trunk/test/Sema/implicit-int.c (original)
+++ cfe/trunk/test/Sema/implicit-int.c Wed Apr 22 00:27:59 2009
@@ -23,8 +23,7 @@
 }
 
 struct foo {
- __extension__ __attribute__((packed)) // expected-warning {{type specifier missing, defaults to 'int'}}
-   x : 4;
+ __extension__ __attribute__((packed)) x : 4; // expected-warning {{type specifier missing, defaults to 'int'}}
 };
 
 





More information about the cfe-commits mailing list