summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-06-20 05:34:32 +0000
committerJordan Rose <jordan_rose@apple.com>2012-06-20 05:34:32 +0000
commit3c4e76d712eac172b100bb10b96637ffca105433 (patch)
tree1cd60dc777581b7c98a5a2e54f70d097e32f2fbc /test
parent1912982993347c8b0b20aed311fca61ce2600479 (diff)
downloadclang-3c4e76d712eac172b100bb10b96637ffca105433.tar.gz
[analyzer] Move failing 'new' test cases back into new.cpp instead of XFAILing.
Per Anna's comment, this is a better way to handle "to-do list"-type failures. This way we'll know if any of the features get fixed; in an XFAIL file, /all/ the cases have to be fixed before lit would tell us anything. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158791 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/Analysis/new-fail.cpp21
-rw-r--r--test/Analysis/new.cpp31
2 files changed, 31 insertions, 21 deletions
diff --git a/test/Analysis/new-fail.cpp b/test/Analysis/new-fail.cpp
deleted file mode 100644
index 8b1903fbea..0000000000
--- a/test/Analysis/new-fail.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc -analyzer-store region -verify %s
-// XFAIL: *
-
-void f1() {
- int *n = new int;
- if (*n) { // expected-warning {{Branch condition evaluates to a garbage value}}
- }
-}
-
-void f2() {
- int *n = new int(3);
- if (*n) { // no-warning
- }
-}
-
-void *operator new(size_t, void *, void *);
-void *testCustomNew() {
- int *x = (int *)malloc(sizeof(int));
- void *y = new (0, x) int;
- return y; // no-warning (placement new could have freed x)
-}
diff --git a/test/Analysis/new.cpp b/test/Analysis/new.cpp
index 3cf5b0f8cc..8093eff3a1 100644
--- a/test/Analysis/new.cpp
+++ b/test/Analysis/new.cpp
@@ -34,3 +34,34 @@ void *testCustomNew() {
return y; // no-warning
}
+
+//--------------------------------
+// Incorrectly-modelled behavior
+//--------------------------------
+
+void testZeroInitialization() {
+ int *n = new int;
+
+ // Should warn that *n is uninitialized.
+ if (*n) { // no-warning
+ }
+}
+
+void testValueInitialization() {
+ int *n = new int(3);
+
+ // Should be TRUE (and have no uninitialized variable warning)
+ clang_analyzer_eval(*n == 3); // expected-warning{{UNKNOWN}}
+}
+
+
+void *operator new(size_t, void *, void *);
+void *testCustomNewMalloc() {
+ int *x = (int *)malloc(sizeof(int));
+
+ // Should be no-warning (the custom allocator could have freed x).
+ void *y = new (0, x) int; // expected-warning{{leak of memory pointed to by 'x'}}
+
+ return y;
+}
+