svn commit: r242080 - in head/contrib/llvm/tools/clang: include/clang/Basic lib/Sema

Ed Schouten ed at FreeBSD.org
Thu Oct 25 10:13:59 UTC 2012


Author: ed
Date: Thu Oct 25 10:13:58 2012
New Revision: 242080
URL: http://svn.freebsd.org/changeset/base/242080

Log:
  Pull in r166498 from upstream clang trunk:
  
  Add a new warning -Wmissing-variable-declarations, to warn about variables
  defined without a previous declaration.  This is similar to
  -Wmissing-prototypes, but for variables instead of functions.

Modified:
  head/contrib/llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td
  head/contrib/llvm/tools/clang/lib/Sema/Sema.cpp
  head/contrib/llvm/tools/clang/lib/Sema/SemaDecl.cpp

Modified: head/contrib/llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td
==============================================================================
--- head/contrib/llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td	Thu Oct 25 09:39:14 2012	(r242079)
+++ head/contrib/llvm/tools/clang/include/clang/Basic/DiagnosticSemaKinds.td	Thu Oct 25 10:13:58 2012	(r242080)
@@ -3058,6 +3058,9 @@ def note_sentinel_here : Note<
 def warn_missing_prototype : Warning<
   "no previous prototype for function %0">,
   InGroup<DiagGroup<"missing-prototypes">>, DefaultIgnore;
+def warn_missing_variable_declarations : Warning<
+  "no previous extern declaration for non-static variable %0">,
+  InGroup<DiagGroup<"missing-variable-declarations">>, DefaultIgnore;
 def err_redefinition : Error<"redefinition of %0">;
 def err_definition_of_implicitly_declared_member : Error<
   "definition of implicitly declared %select{default constructor|copy "

Modified: head/contrib/llvm/tools/clang/lib/Sema/Sema.cpp
==============================================================================
--- head/contrib/llvm/tools/clang/lib/Sema/Sema.cpp	Thu Oct 25 09:39:14 2012	(r242079)
+++ head/contrib/llvm/tools/clang/lib/Sema/Sema.cpp	Thu Oct 25 10:13:58 2012	(r242080)
@@ -648,6 +648,8 @@ void Sema::ActOnEndOfTranslationUnit() {
                                    diag::err_tentative_def_incomplete_type))
       VD->setInvalidDecl();
 
+    CheckCompleteVariableDeclaration(VD);
+
     // Notify the consumer that we've completed a tentative definition.
     if (!VD->isInvalidDecl())
       Consumer.CompleteTentativeDefinition(VD);

Modified: head/contrib/llvm/tools/clang/lib/Sema/SemaDecl.cpp
==============================================================================
--- head/contrib/llvm/tools/clang/lib/Sema/SemaDecl.cpp	Thu Oct 25 09:39:14 2012	(r242079)
+++ head/contrib/llvm/tools/clang/lib/Sema/SemaDecl.cpp	Thu Oct 25 10:13:58 2012	(r242080)
@@ -6957,6 +6957,17 @@ void Sema::CheckCompleteVariableDeclarat
     }
   }
 
+  if (var->isThisDeclarationADefinition() &&
+      var->getLinkage() == ExternalLinkage) {
+    // Find a previous declaration that's not a definition.
+    VarDecl *prev = var->getPreviousDecl();
+    while (prev && prev->isThisDeclarationADefinition())
+      prev = prev->getPreviousDecl();
+
+    if (!prev)
+      Diag(var->getLocation(), diag::warn_missing_variable_declarations) << var;
+  }
+
   // All the following checks are C++ only.
   if (!getLangOpts().CPlusPlus) return;
 


More information about the svn-src-all mailing list