summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/lsan/lit_tests/TestCases/use_unaligned.cc
diff options
context:
space:
mode:
authorSergey Matveev <earthdok@google.com>2013-05-31 13:13:55 +0000
committerSergey Matveev <earthdok@google.com>2013-05-31 13:13:55 +0000
commit5494e0bec303af3557f96fa3e6dff88428b885a8 (patch)
treeb94c17606c512e7b986e6a461bb657b442424c4e /compiler-rt/lib/lsan/lit_tests/TestCases/use_unaligned.cc
parent4717d2d4945ced853b80600e3b0c3490e966da34 (diff)
downloadbcm5719-llvm-5494e0bec303af3557f96fa3e6dff88428b885a8.tar.gz
bcm5719-llvm-5494e0bec303af3557f96fa3e6dff88428b885a8.zip
[lsan] Run the leak detection tests under both ASan and LSan.
Change the LSan lit test logic. Now "check-lsan" tests the leak checking functionality in both standalone LSan and ASan. llvm-svn: 183000
Diffstat (limited to 'compiler-rt/lib/lsan/lit_tests/TestCases/use_unaligned.cc')
-rw-r--r--compiler-rt/lib/lsan/lit_tests/TestCases/use_unaligned.cc23
1 files changed, 23 insertions, 0 deletions
diff --git a/compiler-rt/lib/lsan/lit_tests/TestCases/use_unaligned.cc b/compiler-rt/lib/lsan/lit_tests/TestCases/use_unaligned.cc
new file mode 100644
index 00000000000..75b90d60bd7
--- /dev/null
+++ b/compiler-rt/lib/lsan/lit_tests/TestCases/use_unaligned.cc
@@ -0,0 +1,23 @@
+// Test that unaligned pointers are detected correctly.
+// RUN: LSAN_BASE="report_blocks=1:use_stacks=0:use_registers=0"
+// RUN: %clangxx_lsan %s -o %t
+// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_unaligned=0" %t 2>&1 | FileCheck %s
+// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_unaligned=1" %t 2>&1
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+void *arr[2];
+
+int main() {
+ void *p = malloc(1337);
+ fprintf(stderr, "Test alloc: %p.\n", p);
+ char *char_arr = (char *)arr;
+ memcpy(char_arr + 1, &p, sizeof(p));
+ return 0;
+}
+// CHECK: Test alloc: [[ADDR:.*]].
+// CHECK: LeakSanitizer: detected memory leaks
+// CHECK: Directly leaked 1337 byte block at [[ADDR]]
+// CHECK: SUMMARY: LeakSanitizer:
OpenPOWER on IntegriCloud