From: Ted Kremenek Date: Tue, 6 Mar 2012 23:40:47 +0000 (+0000) Subject: Fix horrific CFG bug where '@autoreleasepool' would be put in a dangling block in... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8e282c332f8ad51dedf86a185a4dcb78ef93fb51;p=clang Fix horrific CFG bug where '@autoreleasepool' would be put in a dangling block in the CFG. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@152163 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index 8ba6d448da..b06cf44344 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -339,6 +339,7 @@ private: CFGBlock *VisitLabelStmt(LabelStmt *L); CFGBlock *VisitMemberExpr(MemberExpr *M, AddStmtChoice asc); CFGBlock *VisitObjCAtCatchStmt(ObjCAtCatchStmt *S); + CFGBlock *VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S); CFGBlock *VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S); CFGBlock *VisitObjCAtThrowStmt(ObjCAtThrowStmt *S); CFGBlock *VisitObjCAtTryStmt(ObjCAtTryStmt *S); @@ -1014,6 +1015,9 @@ CFGBlock *CFGBuilder::Visit(Stmt * S, AddStmtChoice asc) { case Stmt::ObjCAtCatchStmtClass: return VisitObjCAtCatchStmt(cast(S)); + case Stmt::ObjCAutoreleasePoolStmtClass: + return VisitObjCAutoreleasePoolStmt(cast(S)); + case Stmt::ObjCAtSynchronizedStmtClass: return VisitObjCAtSynchronizedStmt(cast(S)); @@ -1929,6 +1933,12 @@ CFGBlock *CFGBuilder::VisitObjCForCollectionStmt(ObjCForCollectionStmt *S) { return addStmt(S->getCollection()); } +CFGBlock *CFGBuilder::VisitObjCAutoreleasePoolStmt(ObjCAutoreleasePoolStmt *S) { + // Inline the body. + return addStmt(S->getSubStmt()); + // TODO: consider adding cleanups for the end of @autoreleasepool scope. +} + CFGBlock *CFGBuilder::VisitObjCAtSynchronizedStmt(ObjCAtSynchronizedStmt *S) { // FIXME: Add locking 'primitives' to CFG for @synchronized. diff --git a/test/SemaObjC/warn-unreachable.m b/test/SemaObjC/warn-unreachable.m new file mode 100644 index 0000000000..832cbd23d2 --- /dev/null +++ b/test/SemaObjC/warn-unreachable.m @@ -0,0 +1,17 @@ +// RUN: %clang %s -fsyntax-only -Xclang -verify -fblocks -Wunreachable-code -Wno-unused-value -Wno-covered-switch-default + +// This previously triggered a warning from -Wunreachable-code because of +// a busted CFG. +typedef signed char BOOL; +BOOL radar10989084() { + @autoreleasepool { // no-warning + return __objc_yes; + } +} + +// Test the warning works. +void test_unreachable() { + return; + return; // expected-warning {{will never be executed}} +} +