[cfe-commits] [PATCH] When marking a function used, also mark the first redeclaration.

Rafael Espíndola rafael.espindola at gmail.com
Mon Dec 24 23:48:25 PST 2012


On 24 December 2012 17:12, Rafael Ávila de Espíndola
<rafael.espindola at gmail.com> wrote:
> This fixes pr14691, which I think is a regression from r168519.
>
> Let me know if you think we should mark all previous decls instead, but as
> far as I can tell we only ever look at the current or at the first decl.

Now that I think of it, it is probably best to just change
ShouldRemoveFromUnused. The attached patch does that.


> ---
>  lib/Sema/SemaExpr.cpp                 |  5 +++++
>  test/SemaCXX/warn-func-not-needed.cpp | 17 +++++++++++++++++
>  2 files changed, 22 insertions(+)
>  create mode 100644 test/SemaCXX/warn-func-not-needed.cpp
>
> diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
> index 191a26d..a5dd1dc 100644
> --- a/lib/Sema/SemaExpr.cpp
> +++ b/lib/Sema/SemaExpr.cpp
> @@ -10497,6 +10497,11 @@ void Sema::MarkFunctionReferenced(SourceLocation Loc, FunctionDecl *Func) {
>    }
>
>    Func->setUsed(true);
> +
> +  // We use the first declaration to keep track of unused global declarations
> +  // (see UnusedFileScopedDecls), so mark it used too.
> +  FunctionDecl *First = Func->getFirstDeclaration();
> +  First->setUsed(true);
>  }
>
>  static void
> diff --git a/test/SemaCXX/warn-func-not-needed.cpp b/test/SemaCXX/warn-func-not-needed.cpp
> new file mode 100644
> index 0000000..437a428
> --- /dev/null
> +++ b/test/SemaCXX/warn-func-not-needed.cpp
> @@ -0,0 +1,17 @@
> +// RUN: %clang_cc1 -fsyntax-only -verify -Wall %s
> +
> +namespace test1 {
> +  static void f() {} // expected-warning {{is not needed and will not be emitted}}
> +  static void f();
> +  template <typename T>
> +  void foo() {
> +    f();
> +  }
> +}
> +
> +namespace test2 {
> +  static void f() {}
> +  static void f();
> +  static void g() { f(); }
> +  void h() { g(); }
> +}
> --
> 1.7.11.7
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: t.patch
Type: application/octet-stream
Size: 1071 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20121225/37b8073d/attachment.obj>


More information about the cfe-commits mailing list