[cfe-commits] r163329 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/Sema/warn-unused-function.c
Ted Kremenek
kremenek at apple.com
Thu Sep 6 10:28:13 PDT 2012
Hi Fariborz,
I see logic here that special cases for Objective-C categories, but no test case for that bit. Is that already covered by an existing test?
Ted
On Sep 6, 2012, at 9:43 AM, Fariborz Jahanian <fjahanian at apple.com> wrote:
> Author: fjahanian
> Date: Thu Sep 6 11:43:18 2012
> New Revision: 163329
>
> URL: http://llvm.org/viewvc/llvm-project?rev=163329&view=rev
> Log:
> c: make __attribute__((unused)) transitive.
> Don't warn if annotated decl is used inside another
> unused. // rdar://12233989
>
> Modified:
> cfe/trunk/lib/Sema/SemaExpr.cpp
> cfe/trunk/test/Sema/warn-unused-function.c
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=163329&r1=163328&r2=163329&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Sep 6 11:43:18 2012
> @@ -66,6 +66,18 @@
> return true;
> }
>
> +static void DiagnoseUnusedOfDecl(Sema &S, NamedDecl *D, SourceLocation Loc) {
> + // Warn if this is used but marked unused.
> + if (D->hasAttr<UnusedAttr>()) {
> + const Decl *DC = cast<Decl>(S.getCurLexicalContext());
> + // A category implicitly has the availability of the interface.
> + if (const ObjCCategoryDecl *CatD = dyn_cast<ObjCCategoryDecl>(DC))
> + DC = CatD->getClassInterface();
> + if (!DC->hasAttr<UnusedAttr>())
> + S.Diag(Loc, diag::warn_used_but_marked_unused) << D->getDeclName();
> + }
> +}
> +
> static AvailabilityResult DiagnoseAvailabilityOfDecl(Sema &S,
> NamedDecl *D, SourceLocation Loc,
> const ObjCInterfaceDecl *UnknownObjCClass) {
> @@ -250,9 +262,7 @@
> }
> DiagnoseAvailabilityOfDecl(*this, D, Loc, UnknownObjCClass);
>
> - // Warn if this is used but marked unused.
> - if (D->hasAttr<UnusedAttr>())
> - Diag(Loc, diag::warn_used_but_marked_unused) << D->getDeclName();
> + DiagnoseUnusedOfDecl(*this, D, Loc);
>
> diagnoseUseOfInternalDeclInInlineFunction(*this, D, Loc);
>
>
> 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=163329&r1=163328&r2=163329&view=diff
> ==============================================================================
> --- cfe/trunk/test/Sema/warn-unused-function.c (original)
> +++ cfe/trunk/test/Sema/warn-unused-function.c Thu Sep 6 11:43:18 2012
> @@ -1,4 +1,4 @@
> -// RUN: %clang_cc1 -fsyntax-only -Wunused-function -Wunneeded-internal-declaration -verify %s
> +// RUN: %clang_cc1 -fsyntax-only -Wused-but-marked-unused -Wunused-function -Wunneeded-internal-declaration -verify %s
> // RUN: %clang_cc1 -fsyntax-only -verify -Wunused %s
> // RUN: %clang_cc1 -fsyntax-only -verify -Wall %s
>
> @@ -54,3 +54,15 @@
> char * const __attribute__((cleanup(cleanupMalloc))) a;
> (void)a;
> }
> +
> +// rdar://12233989
> +extern void a(void) __attribute__((unused));
> +extern void b(void) __attribute__((unused));
> +
> +void b(void)
> +{
> +}
> +void a(void)
> +{
> + b();
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list