summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test/tsan/malloc_overflow.cc
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2014-02-14 14:35:48 +0000
committerAlexey Samsonov <samsonov@google.com>2014-02-14 14:35:48 +0000
commite6a6183e9b8ecf7dec8808fa87577d5b574ca22e (patch)
treea6e5f3181f2e0c4ffc21f9648c5e9c873f34b330 /compiler-rt/test/tsan/malloc_overflow.cc
parent9f20d6703479a952465f7db0c2fbd70904c030c2 (diff)
downloadbcm5719-llvm-e6a6183e9b8ecf7dec8808fa87577d5b574ca22e.tar.gz
bcm5719-llvm-e6a6183e9b8ecf7dec8808fa87577d5b574ca22e.zip
Move TSan lit-tests under test/tsan
llvm-svn: 201414
Diffstat (limited to 'compiler-rt/test/tsan/malloc_overflow.cc')
-rw-r--r--compiler-rt/test/tsan/malloc_overflow.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/compiler-rt/test/tsan/malloc_overflow.cc b/compiler-rt/test/tsan/malloc_overflow.cc
new file mode 100644
index 00000000000..afbebc8bec4
--- /dev/null
+++ b/compiler-rt/test/tsan/malloc_overflow.cc
@@ -0,0 +1,23 @@
+// RUN: %clangxx_tsan -O1 %s -o %t
+// RUN: TSAN_OPTIONS=allocator_may_return_null=1 %t 2>&1 | FileCheck %s
+#include <stdio.h>
+#include <stdlib.h>
+
+int main() {
+ void *p = malloc((size_t)-1);
+ if (p != 0)
+ printf("FAIL malloc(-1) = %p\n", p);
+ p = malloc((size_t)-1 / 2);
+ if (p != 0)
+ printf("FAIL malloc(-1/2) = %p\n", p);
+ p = calloc((size_t)-1, (size_t)-1);
+ if (p != 0)
+ printf("FAIL calloc(-1, -1) = %p\n", p);
+ p = calloc((size_t)-1 / 2, (size_t)-1 / 2);
+ if (p != 0)
+ printf("FAIL calloc(-1/2, -1/2) = %p\n", p);
+ printf("OK\n");
+}
+
+// CHECK-NOT: FAIL
+// CHECK-NOT: failed to allocate
OpenPOWER on IntegriCloud