]> granicus.if.org Git - clang/commitdiff
Fix unused function warning to handle used attributes and redeclarations. Update...
authorTanya Lattner <tonic@nondot.org>
Wed, 17 Feb 2010 02:17:21 +0000 (02:17 +0000)
committerTanya Lattner <tonic@nondot.org>
Wed, 17 Feb 2010 02:17:21 +0000 (02:17 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@96444 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/AST/DeclBase.h
include/clang/Basic/DiagnosticSemaKinds.td
lib/AST/DeclBase.cpp
test/Sema/warn-unused-function.c

index a407a16277473dbefa9fc5338074ec0b7bcc7402..8195fcb253c07c61760ac6c6f1ed9e737b391128 100644 (file)
@@ -279,7 +279,8 @@ public:
 
   /// \brief Whether this declaration was used, meaning that a definition
   /// is required.
-  bool isUsed() const { return Used; }
+  bool isUsed() const;
+  
   void setUsed(bool U = true) { Used = U; }
 
   /// \brief Retrieve the level of precompiled header from which this
index a37177ba344da75d02cd27dd971f8cf9f89cb39e..e2912ea3517ad005d6d57d7c761e6245fa6828e8 100644 (file)
@@ -88,10 +88,8 @@ def warn_decl_in_param_list : Warning<
 def err_array_star_in_function_definition : Error<
   "variable length array must be bound in function definition">;
 def warn_unused_function : Warning<"unused function %0">,
-// FIXME: Temporarily disabled pending PR6321.
-//  InGroup<UnusedFunction>, DefaultIgnore;
-  DefaultIgnore;
-
+  InGroup<UnusedFunction>, DefaultIgnore;
+  
 def warn_implicit_function_decl : Warning<
   "implicit declaration of function %0">,
   InGroup<ImplicitFunctionDeclare>, DefaultIgnore;
index 863a1cbd03c4c12f3c03968de44a0757d63397d8..222adcb28e4ee5139dd9f2498800e92522f440e2 100644 (file)
@@ -194,6 +194,24 @@ ASTContext &Decl::getASTContext() const {
   return getTranslationUnitDecl()->getASTContext();
 }
 
+bool Decl::isUsed() const { 
+  if (Used)
+    return true;
+  
+  // Check for used attribute.
+  if (hasAttr<UsedAttr>())
+    return true;
+  
+  // Check redeclarations for used attribute.
+  for (redecl_iterator I = redecls_begin(), E = redecls_end(); I != E; ++I) {
+    if (I->hasAttr<UsedAttr>() || I->Used)
+      return true;
+  }
+  
+  return false; 
+}
+
+
 unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
   switch (DeclKind) {
     case Function:
index 81ea82dd163b9bcc7f4a0a5c146ee35037741bc1..1a2a50e1aa08a0988601704af76104fd76273de8 100644 (file)
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -fsyntax-only -Wunused-function -verify %s
-// XFAIL: *
 
 void foo() {}
 static void f2() {} 
@@ -14,4 +13,14 @@ extern void f3() { } // expected-warning{{unused}}
 // FIXME: This will trigger a warning when it should not.
 // Update once PR6281 is fixed.
 //inline static void f4();
-//void f4() { } 
+//void f4() { }
+
+static void __attribute__((used)) f5() {}
+static void f6();
+static void __attribute__((used)) f6();
+static void f6() {};
+
+static void f7(void);
+void f8(void(*a0)(void));
+void f9(void) { f8(f7); }
+static void f7(void) {}