summaryrefslogtreecommitdiffstats
path: root/compiler-rt/test
diff options
context:
space:
mode:
authorAlex Shlyapnikov <alekseys@google.com>2018-06-05 18:02:09 +0000
committerAlex Shlyapnikov <alekseys@google.com>2018-06-05 18:02:09 +0000
commit236c3f9c4abd128eb6f2b5ab107764bcbb9df2da (patch)
treeaf2a05be27f4aec695df568bfc112165dec3c407 /compiler-rt/test
parent89f529356a938c01eadd9d3451bfcc9ebbf76d89 (diff)
downloadbcm5719-llvm-236c3f9c4abd128eb6f2b5ab107764bcbb9df2da.tar.gz
bcm5719-llvm-236c3f9c4abd128eb6f2b5ab107764bcbb9df2da.zip
[LSan] Report proper error on allocator failures instead of CHECK(0)-ing
Summary: Following up on and complementing D44404. Currently many allocator specific errors (OOM, for example) are reported as a text message and CHECK(0) termination, not stack, no details, not too helpful nor informative. To improve the situation, detailed and structured errors were defined and reported under the appropriate conditions. Reviewers: eugenis Subscribers: srhines, mgorny, delcypher, llvm-commits, #sanitizers Differential Revision: https://reviews.llvm.org/D47645 llvm-svn: 334034
Diffstat (limited to 'compiler-rt/test')
-rw-r--r--compiler-rt/test/lsan/TestCases/Linux/aligned_alloc-alignment.cc25
-rw-r--r--compiler-rt/test/lsan/TestCases/Posix/lit.local.cfg9
-rw-r--r--compiler-rt/test/lsan/TestCases/Posix/posix_memalign-alignment.cc22
-rw-r--r--compiler-rt/test/lsan/TestCases/allocator_returns_null.cc20
4 files changed, 64 insertions, 12 deletions
diff --git a/compiler-rt/test/lsan/TestCases/Linux/aligned_alloc-alignment.cc b/compiler-rt/test/lsan/TestCases/Linux/aligned_alloc-alignment.cc
new file mode 100644
index 00000000000..370691d5810
--- /dev/null
+++ b/compiler-rt/test/lsan/TestCases/Linux/aligned_alloc-alignment.cc
@@ -0,0 +1,25 @@
+// RUN: %clangxx_lsan -O0 %s -o %t
+// RUN: %env_lsan_opts=allocator_may_return_null=0 not %run %t 2>&1 | FileCheck %s
+// RUN: %env_lsan_opts=allocator_may_return_null=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
+
+// UNSUPPORTED: android
+
+// REQUIRES: stable-runtime
+
+#include <stdio.h>
+#include <stdlib.h>
+
+extern void *aligned_alloc(size_t alignment, size_t size);
+
+int main() {
+ void *p = aligned_alloc(17, 100);
+ // CHECK: {{ERROR: .*Sanitizer: invalid allocation alignment: 17}}
+ // CHECK: {{#0 0x.* in .*}}{{aligned_alloc|memalign}}
+ // CHECK: {{#1 0x.* in main .*aligned_alloc-alignment.cc:}}[[@LINE-3]]
+ // CHECK: {{SUMMARY: .*Sanitizer: invalid-allocation-alignment}}
+
+ printf("pointer after failed aligned_alloc: %zd\n", (size_t)p);
+ // CHECK-NULL: pointer after failed aligned_alloc: 0
+
+ return 0;
+}
diff --git a/compiler-rt/test/lsan/TestCases/Posix/lit.local.cfg b/compiler-rt/test/lsan/TestCases/Posix/lit.local.cfg
new file mode 100644
index 00000000000..60a9460820a
--- /dev/null
+++ b/compiler-rt/test/lsan/TestCases/Posix/lit.local.cfg
@@ -0,0 +1,9 @@
+def getRoot(config):
+ if not config.parent:
+ return config
+ return getRoot(config.parent)
+
+root = getRoot(config)
+
+if root.host_os in ['Windows']:
+ config.unsupported = True
diff --git a/compiler-rt/test/lsan/TestCases/Posix/posix_memalign-alignment.cc b/compiler-rt/test/lsan/TestCases/Posix/posix_memalign-alignment.cc
new file mode 100644
index 00000000000..1b9b14ebe26
--- /dev/null
+++ b/compiler-rt/test/lsan/TestCases/Posix/posix_memalign-alignment.cc
@@ -0,0 +1,22 @@
+// RUN: %clangxx_lsan -O0 %s -o %t
+// RUN: %env_lsan_opts=allocator_may_return_null=0 not %run %t 2>&1 | FileCheck %s
+// RUN: %env_lsan_opts=allocator_may_return_null=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NULL
+
+// REQUIRES: stable-runtime
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main() {
+ void *p = reinterpret_cast<void*>(42);
+ int res = posix_memalign(&p, 17, 100);
+ // CHECK: {{ERROR: .*Sanitizer: invalid alignment requested in posix_memalign: 17}}
+ // CHECK: {{#0 0x.* in .*posix_memalign}}
+ // CHECK: {{#1 0x.* in main .*posix_memalign-alignment.cc:}}[[@LINE-3]]
+ // CHECK: {{SUMMARY: .*Sanitizer: invalid-posix-memalign-alignment}}
+
+ printf("pointer after failed posix_memalign: %zd\n", (size_t)p);
+ // CHECK-NULL: pointer after failed posix_memalign: 42
+
+ return 0;
+}
diff --git a/compiler-rt/test/lsan/TestCases/allocator_returns_null.cc b/compiler-rt/test/lsan/TestCases/allocator_returns_null.cc
index 722cc5c4e18..fee90f724f0 100644
--- a/compiler-rt/test/lsan/TestCases/allocator_returns_null.cc
+++ b/compiler-rt/test/lsan/TestCases/allocator_returns_null.cc
@@ -36,10 +36,6 @@
// RUN: %env_lsan_opts=allocator_may_return_null=1 %run %t new-nothrow 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-nnNULL
-// TODO(alekseyshl): Enable it back for standalone LSan mode when CHECK(0) in
-// LSan allocator are converted to proper errors (see D44404 for the reference).
-// REQUIRES: asan
-
#include <assert.h>
#include <errno.h>
#include <stdio.h>
@@ -102,21 +98,21 @@ int main(int argc, char **argv) {
}
// CHECK-mCRASH: malloc:
-// CHECK-mCRASH: SUMMARY: AddressSanitizer: allocation-size-too-big
+// CHECK-mCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big}}
// CHECK-cCRASH: calloc:
-// CHECK-cCRASH: SUMMARY: AddressSanitizer: allocation-size-too-big
+// CHECK-cCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big}}
// CHECK-coCRASH: calloc-overflow:
-// CHECK-coCRASH: SUMMARY: AddressSanitizer: calloc-overflow
+// CHECK-coCRASH: {{SUMMARY: .*Sanitizer: calloc-overflow}}
// CHECK-rCRASH: realloc:
-// CHECK-rCRASH: SUMMARY: AddressSanitizer: allocation-size-too-big
+// CHECK-rCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big}}
// CHECK-mrCRASH: realloc-after-malloc:
-// CHECK-mrCRASH: SUMMARY: AddressSanitizer: allocation-size-too-big
+// CHECK-mrCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big}}
// CHECK-nCRASH: new:
-// CHECK-nCRASH: SUMMARY: AddressSanitizer: allocation-size-too-big
+// CHECK-nCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big}}
// CHECK-nCRASH-OOM: new:
-// CHECK-nCRASH-OOM: SUMMARY: AddressSanitizer: out-of-memory
+// CHECK-nCRASH-OOM: {{SUMMARY: .*Sanitizer: out-of-memory}}
// CHECK-nnCRASH: new-nothrow:
-// CHECK-nnCRASH: SUMMARY: AddressSanitizer: allocation-size-too-big
+// CHECK-nnCRASH: {{SUMMARY: .*Sanitizer: allocation-size-too-big}}
// CHECK-mNULL: malloc:
// CHECK-mNULL: errno: 12
OpenPOWER on IntegriCloud