summaryrefslogtreecommitdiff
path: root/clang/test/Analysis/idempotent-operations.m
diff options
context:
space:
mode:
authorZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
committerZancanaro; Carlo <czan8762@plang3.cs.usyd.edu.au>2012-09-24 09:58:17 +1000
commit222e2a7620e6520ffaf4fc4e69d79c18da31542e (patch)
tree7bfbc05bfa3b41c8f9d2e56d53a0bc3e310df239 /clang/test/Analysis/idempotent-operations.m
parent3d206f03985b50beacae843d880bccdc91a9f424 (diff)
Add the clang library to the repo (with some of my changes, too).
Diffstat (limited to 'clang/test/Analysis/idempotent-operations.m')
-rw-r--r--clang/test/Analysis/idempotent-operations.m54
1 files changed, 54 insertions, 0 deletions
diff --git a/clang/test/Analysis/idempotent-operations.m b/clang/test/Analysis/idempotent-operations.m
new file mode 100644
index 0000000..9a9820c
--- /dev/null
+++ b/clang/test/Analysis/idempotent-operations.m
@@ -0,0 +1,54 @@
+// RUN: %clang_cc1 -analyze -analyzer-store=region -analyzer-constraints=range -fblocks -analyzer-opt-analyze-nested-blocks -analyzer-checker=experimental.deadcode.IdempotentOperations,osx.cocoa.RetainCount -verify %s
+
+typedef signed char BOOL;
+typedef unsigned long NSUInteger;
+typedef struct _NSZone NSZone;
+@protocol NSObject - (BOOL)isEqual:(id)object;
+@end
+
+@interface NSObject {}
+ @property int locked;
+ @property(nonatomic, readonly) NSObject *media;
+@end
+
+// <rdar://problem/8725041> - Don't flag idempotent operation warnings when
+// a method may invalidate an instance variable.
+@interface Rdar8725041 : NSObject {
+ id _attribute;
+}
+ - (void) method2;
+@end
+
+@implementation Rdar8725041
+- (BOOL) method1 {
+ BOOL needsUpdate = (BOOL)0;
+ id oldAttribute = _attribute;
+ [self method2];
+ needsUpdate |= (_attribute != oldAttribute); // no-warning
+ return needsUpdate;
+}
+
+- (void) method2
+{
+ _attribute = ((void*)0);
+}
+@end
+
+// Test that the idempotent operations checker works in the prescence
+// of property expressions.
+void pr9116(NSObject *placeholder) {
+ int x = placeholder.media.locked = placeholder ? 1 : 0;
+}
+
+// <rdar://problem/9130239>: Test that calling property setters doesn't
+// trigger an assertion failure when the object is nil.
+@interface RDar9130239
+@property (assign) id delegate;
+@end
+
+void test_RDar9130239(RDar9130239 *x) {
+ if (x)
+ return;
+ x.delegate = x; // no-warning
+}
+