]> granicus.if.org Git - clang/commitdiff
c: make __attribute__((unused)) transitive.
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 6 Sep 2012 16:43:18 +0000 (16:43 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 6 Sep 2012 16:43:18 +0000 (16:43 +0000)
   Don't warn if annotated decl is used inside another
   unused. // rdar://12233989

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163329 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/Sema/warn-unused-function.c

index 57dab09e46d2dc59d659856ccd9fedfe17d569dd..a67d5c6bd09a63e27d67bb35da4fcd43803daeae 100644 (file)
@@ -66,6 +66,18 @@ bool Sema::CanUseDecl(NamedDecl *D) {
   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 @@ bool Sema::DiagnoseUseOfDecl(NamedDecl *D, SourceLocation Loc,
   }
   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);
 
index 8f4cdcba881e4046af776e356fe4dc400adfe97e..a334e71e50673a64b0c4f45d0d33601bcf78757c 100644 (file)
@@ -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 @@ void f13(void) {
   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();
+}