r193202 - Consider hidden decls for isUsed checks.
Rafael Espindola
rafael.espindola at gmail.com
Tue Oct 22 14:56:29 PDT 2013
Author: rafael
Date: Tue Oct 22 16:56:29 2013
New Revision: 193202
URL: http://llvm.org/viewvc/llvm-project?rev=193202&view=rev
Log:
Consider hidden decls for isUsed checks.
This fixes pr17624.
A FIXME from Richard Smith:
It seems to me that the root cause is that a per-Decl 'used' flag doesn't
really make much sense in the way we use it now. I think we should either track
whether that particular declaration is used (with isUsed scanning the entire
redecl chain), or we should only have one flag for the entire redeclaration
chain (perhaps by always looking at the flag on either the most recent decl or
the canonical decl). Modeling it as "is this declaration or any previous
declaration used" is weird, and requires contortions like the loop at the end
of Sema::MarkFunctionReferenced.
Added:
cfe/trunk/test/Sema/warn-variable-not-needed.c
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=193202&r1=193201&r2=193202&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Oct 22 16:56:29 2013
@@ -2788,7 +2788,7 @@ bool Sema::MergeCompatibleFunctionDecls(
New->setPure();
// Merge "used" flag.
- New->setIsUsed(Old->isUsed(false));
+ New->setIsUsed(Old->getMostRecentDecl()->isUsed(false));
// Merge attributes from the parameters. These can mismatch with K&R
// declarations.
@@ -3101,7 +3101,7 @@ void Sema::MergeVarDecl(VarDecl *New, Lo
}
// Merge "used" flag.
- New->setIsUsed(Old->isUsed(false));
+ New->setIsUsed(Old->getMostRecentDecl()->isUsed(false));
// Keep a chain of previous declarations.
New->setPreviousDecl(Old);
Added: cfe/trunk/test/Sema/warn-variable-not-needed.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-variable-not-needed.c?rev=193202&view=auto
==============================================================================
--- cfe/trunk/test/Sema/warn-variable-not-needed.c (added)
+++ cfe/trunk/test/Sema/warn-variable-not-needed.c Tue Oct 22 16:56:29 2013
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wall %s
+// expected-no-diagnostics
+
+static int a;
+int bar() {
+ extern int a;
+ return a;
+}
+static int a;
Modified: cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp?rev=193202&r1=193201&r2=193202&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-func-not-needed.cpp Tue Oct 22 16:56:29 2013
@@ -42,3 +42,12 @@ namespace test4 {
g<int>();
}
}
+
+namespace test4 {
+ static void func();
+ void bar() {
+ void func();
+ func();
+ }
+ static void func() {}
+}
More information about the cfe-commits
mailing list