r194663 - Refine -Wunused-variable to only suppress warning for __bridge_transfer, not all bridge casts.
Ted Kremenek
kremenek at apple.com
Wed Nov 13 20:27:00 PST 2013
Author: kremenek
Date: Wed Nov 13 22:27:00 2013
New Revision: 194663
URL: http://llvm.org/viewvc/llvm-project?rev=194663&view=rev
Log:
Refine -Wunused-variable to only suppress warning for __bridge_transfer, not all bridge casts.
Also refine test case to capture the intention of this suppression. Essentially
some developers use __bridge_transfer as if it were a safe CFRelease.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaObjC/arc-bridged-cast.m
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=194663&r1=194662&r2=194663&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Nov 13 22:27:00 2013
@@ -1313,26 +1313,16 @@ static bool ShouldDiagnoseUnusedDecl(con
}
}
- // Under ARC, bridged casts can have side-effects on memory
- // management semantics. Some users assign a bridged
- // value to a temporary to adjust reference counts.
+ // Under ARC, some users use __bridge_transfer to automate memory
+ // reclamation of objects that were referenced via C pointers.
const Expr *Init = VD->getInit();
if (Init) {
if (const ExprWithCleanups *EC = dyn_cast<ExprWithCleanups>(Init))
Init = EC->getSubExpr();
Init = Init->IgnoreParens();
- if (const ImplicitCastExpr *IC = dyn_cast<ImplicitCastExpr>(Init)) {
- switch (IC->getCastKind()) {
- case CK_ARCProduceObject:
- case CK_ARCConsumeObject:
- case CK_ARCReclaimReturnedObject:
- case CK_ARCExtendBlockObject:
- case CK_CopyAndAutoreleaseBlockObject:
+ if (const ImplicitCastExpr *IC = dyn_cast<ImplicitCastExpr>(Init))
+ if (IC->getCastKind() == CK_ARCConsumeObject)
return false;
- default:
- break;
- }
- }
}
// TODO: __attribute__((unused)) templates?
Modified: cfe/trunk/test/SemaObjC/arc-bridged-cast.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc-bridged-cast.m?rev=194663&r1=194662&r2=194663&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/arc-bridged-cast.m (original)
+++ cfe/trunk/test/SemaObjC/arc-bridged-cast.m Wed Nov 13 22:27:00 2013
@@ -64,13 +64,12 @@ CFTypeRef fixitsWithSpace(id obj) {
}
// <rdar://problem/15432770>
-// Suppressed -Wunused-variable when the initializer is a bridge cast.
+// Suppressed -Wunused-variable when the initializer is a __bridge_transfer cast.
#pragma clang diagnostic push
#pragma clang diagnostic warning "-Wunused-variable"
-void rdar15432770() {
- void (^block1)() = ^ { };
- void *ptr = (__bridge_retained void *)(block1);
- void (^block2)() = (__bridge_transfer void(^)())ptr; // no-warning
- int x = 1; // expected-warning {{unused variable}}
+void rdar15432770_ptr_release(const void *ptr) {
+ void (^block)() = (__bridge_transfer void(^)())ptr; // no-warning
+ // Test that warning is active.
+ int x = 1; // expected-warning {{unused}}
}
#pragma clang diagnostic pop
More information about the cfe-commits
mailing list