[cfe-commits] r96444 - in /cfe/trunk: include/clang/AST/DeclBase.h include/clang/Basic/DiagnosticSemaKinds.td lib/AST/DeclBase.cpp test/Sema/warn-unused-function.c
Tanya Lattner
tonic at nondot.org
Tue Feb 16 18:17:21 PST 2010
Author: tbrethou
Date: Tue Feb 16 20:17:21 2010
New Revision: 96444
URL: http://llvm.org/viewvc/llvm-project?rev=96444&view=rev
Log:
Fix unused function warning to handle used attributes and redeclarations. Update test case.
Modified:
cfe/trunk/include/clang/AST/DeclBase.h
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/AST/DeclBase.cpp
cfe/trunk/test/Sema/warn-unused-function.c
Modified: cfe/trunk/include/clang/AST/DeclBase.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclBase.h?rev=96444&r1=96443&r2=96444&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclBase.h (original)
+++ cfe/trunk/include/clang/AST/DeclBase.h Tue Feb 16 20:17:21 2010
@@ -279,7 +279,8 @@
/// \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
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=96444&r1=96443&r2=96444&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Feb 16 20:17:21 2010
@@ -88,10 +88,8 @@
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;
Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=96444&r1=96443&r2=96444&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Tue Feb 16 20:17:21 2010
@@ -194,6 +194,24 @@
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:
Modified: cfe/trunk/test/Sema/warn-unused-function.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-unused-function.c?rev=96444&r1=96443&r2=96444&view=diff
==============================================================================
--- cfe/trunk/test/Sema/warn-unused-function.c (original)
+++ cfe/trunk/test/Sema/warn-unused-function.c Tue Feb 16 20:17:21 2010
@@ -1,5 +1,4 @@
// RUN: %clang_cc1 -fsyntax-only -Wunused-function -verify %s
-// XFAIL: *
void foo() {}
static void f2() {}
@@ -14,4 +13,14 @@
// 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) {}
More information about the cfe-commits
mailing list