From ce0e3f8a0920b72703b13a032a1809fae65423ee Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 9 Jan 2014 20:19:45 +0000 Subject: [PATCH] Have attribute 'objc_precise_lifetime' suppress -Wunused. Fixes 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. llvm-svn: 198888 --- clang/lib/Sema/SemaDecl.cpp | 3 ++- clang/test/SemaObjC/unused.m | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index fb041ed..78ead1e 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1268,7 +1268,8 @@ static bool ShouldDiagnoseUnusedDecl(const NamedDecl *D) { if (D->isInvalidDecl()) return false; - if (D->isReferenced() || D->isUsed() || D->hasAttr()) + if (D->isReferenced() || D->isUsed() || D->hasAttr() || + D->hasAttr()) return false; if (isa(D)) diff --git a/clang/test/SemaObjC/unused.m b/clang/test/SemaObjC/unused.m index 3fd1cf0..16a3899 100644 --- a/clang/test/SemaObjC/unused.m +++ b/clang/test/SemaObjC/unused.m @@ -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(); +} + -- 2.7.4