From 03648657c7327175f0e6349fb7a83115a0562d9d Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Thu, 3 Jul 2008 22:25:27 +0000 Subject: [PATCH] Fix a bug in the dead stores checker reported in the following email: http://lists.cs.uiuc.edu/pipermail/cfe-dev/2008-July/002157.html Essentially the observer mechanism in LiveVariables was observing block-level expressions multiple times, leading to a case where the dead store checker could see a value as dead when it was really live. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@53115 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/LiveVariables.cpp | 14 ++++++++++--- test/Analysis/dead-stores.m | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 test/Analysis/dead-stores.m diff --git a/lib/Analysis/LiveVariables.cpp b/lib/Analysis/LiveVariables.cpp index 54e2195a77..8f391dc561 100644 --- a/lib/Analysis/LiveVariables.cpp +++ b/lib/Analysis/LiveVariables.cpp @@ -133,15 +133,23 @@ public: }; void TransferFuncs::Visit(Stmt *S) { - if (AD.Observer) - AD.Observer->ObserveStmt(S,AD,LiveState); if (S == getCurrentBlkStmt()) { + + if (AD.Observer) + AD.Observer->ObserveStmt(S,AD,LiveState); + if (getCFG().isBlkExpr(S)) LiveState(S,AD) = Dead; StmtVisitor::Visit(S); } - else if (!getCFG().isBlkExpr(S)) + else if (!getCFG().isBlkExpr(S)) { + + if (AD.Observer) + AD.Observer->ObserveStmt(S,AD,LiveState); + StmtVisitor::Visit(S); + + } else // For block-level expressions, mark that they are live. LiveState(S,AD) = Alive; diff --git a/test/Analysis/dead-stores.m b/test/Analysis/dead-stores.m new file mode 100644 index 0000000000..f58c2c135f --- /dev/null +++ b/test/Analysis/dead-stores.m @@ -0,0 +1,36 @@ +// RUN: clang -warn-dead-stores -verify %s + +typedef signed char BOOL; +typedef unsigned int NSUInteger; +typedef struct _NSZone NSZone; +@class NSInvocation, NSMethodSignature, NSCoder, NSString, NSEnumerator; +@protocol NSObject - (BOOL)isEqual:(id)object; @end +@protocol NSCopying - (id)copyWithZone:(NSZone *)zone; @end +@protocol NSCoding - (void)encodeWithCoder:(NSCoder *)aCoder; @end +@interface NSObject {} @end +extern id NSAllocateObject(Class aClass, NSUInteger extraBytes, NSZone *zone); +@interface NSValue : NSObject - (void)getValue:(void *)value; @end +typedef float CGFloat; +typedef struct _NSPoint {} NSRange; +@interface NSValue (NSValueRangeExtensions) + (NSValue *)valueWithRange:(NSRange)range; +- (BOOL)containsObject:(id)anObject; +@end +@class NSURLAuthenticationChallenge; +@interface NSResponder : NSObject {} @end +@class NSArray, NSDictionary, NSString; +@interface NSObject (NSKeyValueBindingCreation) ++ (void)exposeBinding:(NSString *)binding; +- (NSArray *)exposedBindings; +@end +extern NSString *NSAlignmentBinding; + +// This test case was reported as a false positive due to a bug in the +// LiveVariables <-> DeadStores interplay. We should not flag a warning +// here. The test case was reported in: +// http://lists.cs.uiuc.edu/pipermail/cfe-dev/2008-July/002157.html +void DeadStoreTest(NSObject *anObject) { + NSArray *keys; + if ((keys = [anObject exposedBindings]) && // no-warning + ([keys containsObject:@"name"] && [keys containsObject:@"icon"])) {} +} + -- 2.40.0