summaryrefslogtreecommitdiffstats
path: root/test/Analysis
diff options
context:
space:
mode:
authorrdivacky <rdivacky@FreeBSD.org>2010-03-03 17:28:16 +0000
committerrdivacky <rdivacky@FreeBSD.org>2010-03-03 17:28:16 +0000
commitdf90325d4c0a65ee64d2dae3ed9b5b34f7418533 (patch)
treee1a885aadfd80632f5bd70d4bd2d37e715e35a79 /test/Analysis
parentfd035e6496665b1f1197868e21cb0a4594e8db6e (diff)
downloadFreeBSD-src-df90325d4c0a65ee64d2dae3ed9b5b34f7418533.zip
FreeBSD-src-df90325d4c0a65ee64d2dae3ed9b5b34f7418533.tar.gz
Update clang to 97654.
Diffstat (limited to 'test/Analysis')
-rw-r--r--test/Analysis/blocks.m5
-rw-r--r--test/Analysis/dead-stores.m7
-rw-r--r--test/Analysis/inline.c20
-rw-r--r--test/Analysis/inline2.c14
-rw-r--r--test/Analysis/misc-ps-region-store.m21
-rw-r--r--test/Analysis/retain-release.m22
-rw-r--r--test/Analysis/unix-fns.c19
-rw-r--r--test/Analysis/unused-ivars.m15
8 files changed, 123 insertions, 0 deletions
diff --git a/test/Analysis/blocks.m b/test/Analysis/blocks.m
index e8e96a2..b05b198 100644
--- a/test/Analysis/blocks.m
+++ b/test/Analysis/blocks.m
@@ -83,3 +83,8 @@ void test2_b() {
// 'x' is bound at block creation.
^{ y = x + 1; }(); // no-warning
}
+
+void test2_c() {
+ typedef void (^myblock)(void);
+ myblock f = ^() { f(); }; // expected-warning{{Variable 'f' is captured by block with a garbage value}}
+} \ No newline at end of file
diff --git a/test/Analysis/dead-stores.m b/test/Analysis/dead-stores.m
index 765a24a..701e580 100644
--- a/test/Analysis/dead-stores.m
+++ b/test/Analysis/dead-stores.m
@@ -34,3 +34,10 @@ void DeadStoreTest(NSObject *anObject) {
([keys containsObject:@"name"] && [keys containsObject:@"icon"])) {}
}
+// This test case was a false positive due to how clang models
+// pointer types and ObjC object pointer types differently. Here
+// we don't warn about a dead store because 'nil' is assigned to
+// an object pointer for the sake of defensive programming.
+void rdar_7631278(NSObject *x) {
+ x = ((void*)0);
+}
diff --git a/test/Analysis/inline.c b/test/Analysis/inline.c
new file mode 100644
index 0000000..13d4f7f
--- /dev/null
+++ b/test/Analysis/inline.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -analyze -inline-call -analyzer-store region -analyze-function f2 -verify %s
+
+int f1() {
+ int y = 1;
+ y++;
+ return y;
+}
+
+void f2() {
+ int x = 1;
+ x = f1();
+ if (x == 1) {
+ int *p = 0;
+ *p = 3; // no-warning
+ }
+ if (x == 2) {
+ int *p = 0;
+ *p = 3; // expected-warning{{Dereference of null pointer loaded from variable}}
+ }
+}
diff --git a/test/Analysis/inline2.c b/test/Analysis/inline2.c
new file mode 100644
index 0000000..e2758c1
--- /dev/null
+++ b/test/Analysis/inline2.c
@@ -0,0 +1,14 @@
+// RUN: %clang_cc1 -analyze -inline-call -analyzer-store region -analyze-function f2 -verify %s
+
+// Test parameter 'a' is registered to LiveVariables analysis data although it
+// is not referenced in the function body.
+// Before processing 'return 1;', in RemoveDeadBindings(), we query the liveness
+// of 'a', because we have a binding for it due to parameter passing.
+int f1(int a) {
+ return 1;
+}
+
+void f2() {
+ int x;
+ x = f1(1);
+}
diff --git a/test/Analysis/misc-ps-region-store.m b/test/Analysis/misc-ps-region-store.m
index 201cbc9..21a54c3 100644
--- a/test/Analysis/misc-ps-region-store.m
+++ b/test/Analysis/misc-ps-region-store.m
@@ -1,6 +1,10 @@
// RUN: %clang_cc1 -triple i386-apple-darwin9 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s
// RUN: %clang_cc1 -triple x86_64-apple-darwin9 -DTEST_64 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -verify -fblocks -analyzer-opt-analyze-nested-blocks %s
+typedef long unsigned int size_t;
+void *memcpy(void *, const void *, size_t);
+void *alloca(size_t);
+
typedef struct objc_selector *SEL;
typedef signed char BOOL;
typedef int NSInteger;
@@ -867,3 +871,20 @@ int test_c_rev96062() {
test_a_rev96062_aux2(&z);
return a + b; // no-warning
}
+
+//===----------------------------------------------------------------------===//
+// <rdar://problem/7242010> - The access to y[0] at the bottom previously
+// was reported as an uninitialized value.
+//===----------------------------------------------------------------------===//
+
+char *rdar_7242010(int count, char **y) {
+ char **x = alloca((count + 4) * sizeof(*x));
+ x[0] = "hi";
+ x[1] = "there";
+ x[2] = "every";
+ x[3] = "body";
+ memcpy(x + 4, y, count * sizeof(*x));
+ y = x;
+ return y[0]; // no-warning
+}
+
diff --git a/test/Analysis/retain-release.m b/test/Analysis/retain-release.m
index 1c41d85..675e9a6 100644
--- a/test/Analysis/retain-release.m
+++ b/test/Analysis/retain-release.m
@@ -7,6 +7,12 @@
#if __has_feature(attribute_cf_returns_retained)
#define CF_RETURNS_RETAINED __attribute__((cf_returns_retained))
#endif
+#if __has_feature(attribute_ns_returns_not_retained)
+#define NS_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained))
+#endif
+#if __has_feature(attribute_cf_returns_not_retained)
+#define CF_RETURNS_NOT_RETAINED __attribute__((cf_returns_not_retained))
+#endif
//===----------------------------------------------------------------------===//
// The following code is reduced using delta-debugging from Mac OS X headers:
@@ -1188,6 +1194,8 @@ typedef NSString* MyStringTy;
- (NSString*) returnsAnOwnedString NS_RETURNS_RETAINED; // no-warning
- (NSString*) returnsAnOwnedCFString CF_RETURNS_RETAINED; // no-warning
- (MyStringTy) returnsAnOwnedTypedString NS_RETURNS_RETAINED; // no-warning
+- (NSString*) newString NS_RETURNS_NOT_RETAINED; // no-warning
+- (NSString*) newStringNoAttr;
- (int) returnsAnOwnedInt NS_RETURNS_RETAINED; // expected-warning{{'ns_returns_retained' attribute only applies to functions or methods that return a pointer or Objective-C object}}
@end
@@ -1201,9 +1209,16 @@ void test_attr_1b(TestOwnershipAttr *X) {
NSString *str = [X returnsAnOwnedCFString]; // expected-warning{{leak}}
}
+void test_attr1c(TestOwnershipAttr *X) {
+ NSString *str = [X newString]; // no-warning
+ NSString *str2 = [X newStringNoAttr]; // expected-warning{{leak}}
+}
+
@interface MyClassTestCFAttr : NSObject {}
- (NSDate*) returnsCFRetained CF_RETURNS_RETAINED;
- (CFDateRef) returnsCFRetainedAsCF CF_RETURNS_RETAINED;
+- (CFDateRef) newCFRetainedAsCF CF_RETURNS_NOT_RETAINED;
+- (CFDateRef) newCFRetainedAsCFNoAttr;
- (NSDate*) alsoReturnsRetained;
- (CFDateRef) alsoReturnsRetainedAsCF;
- (NSDate*) returnsNSRetained NS_RETURNS_RETAINED;
@@ -1223,6 +1238,13 @@ CFDateRef returnsRetainedCFDate() {
return returnsRetainedCFDate(); // No leak.
}
+- (CFDateRef) newCFRetainedAsCF {
+ return (CFDateRef)[(id)[self returnsCFRetainedAsCF] autorelease];
+}
+
+- (CFDateRef) newCFRetainedAsCFNoAttr {
+ return (CFDateRef)[(id)[self returnsCFRetainedAsCF] autorelease]; // expected-warning{{Object with +0 retain counts returned to caller where a +1 (owning) retain count is expected}}
+}
- (NSDate*) alsoReturnsRetained {
return (NSDate*) returnsRetainedCFDate(); // expected-warning{{leak}}
diff --git a/test/Analysis/unix-fns.c b/test/Analysis/unix-fns.c
new file mode 100644
index 0000000..777ad19
--- /dev/null
+++ b/test/Analysis/unix-fns.c
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem %s -analyzer-store=region
+// RUN: %clang_cc1 -analyze -analyzer-check-objc-mem %s -analyzer-store=basic
+
+#ifndef O_CREAT
+#define O_CREAT 0x0200
+#define O_RDONLY 0x0000
+#endif
+int open(const char *, int, ...);
+
+void test_open(const char *path) {
+ int fd;
+ fd = open(path, O_RDONLY); // no-warning
+ if (!fd)
+ close(fd);
+
+ fd = open(path, O_CREAT); // expected-warning{{Call to 'open' requires a third argument when the 'O_CREAT' flag is set}}
+ if (!fd)
+ close(fd);
+}
diff --git a/test/Analysis/unused-ivars.m b/test/Analysis/unused-ivars.m
index 600f0e2..14c43a8 100644
--- a/test/Analysis/unused-ivars.m
+++ b/test/Analysis/unused-ivars.m
@@ -81,3 +81,18 @@ int radar_7254495(RDar7254495 *a) {
return a->x;
}
@end
+
+//===----------------------------------------------------------------------===//
+// <rdar://problem/7353683> - consult attribute((unused)) to silence warnings
+// about unused instance variables
+//===----------------------------------------------------------------------===//
+
+@interface RDar7353683 {
+@private
+ id x __attribute__((unused));
+}
+@end
+
+@implementation RDar7353683
+@end
+
OpenPOWER on IntegriCloud