+++ /dev/null
-// 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)
-}
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;
+}
+