]> granicus.if.org Git - clang/commitdiff
Have attribute 'objc_precise_lifetime' suppress -Wunused.
authorTed Kremenek <kremenek@apple.com>
Thu, 9 Jan 2014 20:19:45 +0000 (20:19 +0000)
committerTed Kremenek <kremenek@apple.com>
Thu, 9 Jan 2014 20:19:45 +0000 (20:19 +0000)
Fixes <rdar://problem/15596883>

In ARC, __attribute__((objc_precise_lifetime)) guarantees that the
object stored in it will survive to the end of the variable's formal
lifetime.  It is therefore useful even if it completely unused.

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

lib/Sema/SemaDecl.cpp
test/SemaObjC/unused.m

index fb041ed98c85470f2eb10807d7eca3aa004f0eec..78ead1ee92b6eddb50a5a156c428896cac0f88e8 100644 (file)
@@ -1268,7 +1268,8 @@ static bool ShouldDiagnoseUnusedDecl(const NamedDecl *D) {
   if (D->isInvalidDecl())
     return false;
 
-  if (D->isReferenced() || D->isUsed() || D->hasAttr<UnusedAttr>())
+  if (D->isReferenced() || D->isUsed() || D->hasAttr<UnusedAttr>() ||
+      D->hasAttr<ObjCPreciseLifetimeAttr>())
     return false;
 
   if (isa<LabelDecl>(D))
index 3fd1cf04673f46cee272aad454c89ce346db42e6..16a38995ffd9361a06e61369825bec43ba761aa2 100644 (file)
@@ -72,3 +72,12 @@ static NSString *x = @"hi"; // expected-warning {{unused variable 'x'}}
 - (void) b {}
 - (void) a { [self b]; }
 @end
+
+// Test that objc_precise_lifetime suppresses
+// unused variable warnings.
+extern void rdar15596883_foo(void);
+void rdar15596883(id x) {
+  __attribute__((objc_precise_lifetime)) id y = x; // no-warning
+  rdar15596883_foo();
+}
+