diff options
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 9281951a814..a7b37c55e92 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -1313,6 +1313,28 @@ static bool ShouldDiagnoseUnusedDecl(const NamedDecl *D) { } } + // 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. + 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: + return false; + default: + break; + } + } + } + // TODO: __attribute__((unused)) templates? } |