[cfe-commits] r100872 - in /cfe/trunk: lib/Sema/Sema.cpp test/SemaCXX/unused-functions.cpp

Douglas Gregor dgregor at apple.com
Fri Apr 9 10:41:13 PDT 2010


Author: dgregor
Date: Fri Apr  9 12:41:13 2010
New Revision: 100872

URL: http://llvm.org/viewvc/llvm-project?rev=100872&view=rev
Log:
Remove all "used" static functions *after* we have performed all of
the implicit template instantiations we need to perform. Otherwise, we
end up erroneously diagnosing static functions as used if they were
only used within an implicit template instantiation. Fixes a bunch of
spurious failures when building Clang with Clang.


Added:
    cfe/trunk/test/SemaCXX/unused-functions.cpp
Modified:
    cfe/trunk/lib/Sema/Sema.cpp

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=100872&r1=100871&r2=100872&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Fri Apr  9 12:41:13 2010
@@ -197,14 +197,7 @@
 /// ActOnEndOfTranslationUnit - This is called at the very end of the
 /// translation unit when EOF is reached and all but the top-level scope is
 /// popped.
-void Sema::ActOnEndOfTranslationUnit() {
-  
-  // Remove functions that turned out to be used.
-  UnusedStaticFuncs.erase(std::remove_if(UnusedStaticFuncs.begin(), 
-                                         UnusedStaticFuncs.end(), 
-                                         std::mem_fun(&FunctionDecl::isUsed)), 
-                          UnusedStaticFuncs.end());
-  
+void Sema::ActOnEndOfTranslationUnit() {  
   while (1) {
     // C++: Perform implicit template instantiations.
     //
@@ -225,6 +218,12 @@
       break;
   }
   
+  // Remove functions that turned out to be used.
+  UnusedStaticFuncs.erase(std::remove_if(UnusedStaticFuncs.begin(), 
+                                         UnusedStaticFuncs.end(), 
+                                         std::mem_fun(&FunctionDecl::isUsed)), 
+                          UnusedStaticFuncs.end());
+
   // Check for #pragma weak identifiers that were never declared
   // FIXME: This will cause diagnostics to be emitted in a non-determinstic
   // order!  Iterating over a densemap like this is bad.

Added: cfe/trunk/test/SemaCXX/unused-functions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/unused-functions.cpp?rev=100872&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/unused-functions.cpp (added)
+++ cfe/trunk/test/SemaCXX/unused-functions.cpp Fri Apr  9 12:41:13 2010
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused -verify %s
+
+static int foo(int x) { return x; }
+
+template<typename T>
+T get_from_foo(T y) { return foo(y); }
+
+int g(int z) { return get_from_foo(z); }





More information about the cfe-commits mailing list