[compiler-rt] r199723 - [asan] one more test for https://code.google.com/p/address-sanitizer/issues/detail?id=258
Kostya Serebryany
kcc at google.com
Tue Jan 21 02:57:07 PST 2014
Author: kcc
Date: Tue Jan 21 04:57:07 2014
New Revision: 199723
URL: http://llvm.org/viewvc/llvm-project?rev=199723&view=rev
Log:
[asan] one more test for https://code.google.com/p/address-sanitizer/issues/detail?id=258
Added:
compiler-rt/trunk/lib/asan/lit_tests/TestCases/throw_catch.cc
Added: compiler-rt/trunk/lib/asan/lit_tests/TestCases/throw_catch.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/lit_tests/TestCases/throw_catch.cc?rev=199723&view=auto
==============================================================================
--- compiler-rt/trunk/lib/asan/lit_tests/TestCases/throw_catch.cc (added)
+++ compiler-rt/trunk/lib/asan/lit_tests/TestCases/throw_catch.cc Tue Jan 21 04:57:07 2014
@@ -0,0 +1,75 @@
+// RUN: %clangxx_asan -O %s -o %t && %t
+
+#include <assert.h>
+#include <setjmp.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <sanitizer/asan_interface.h>
+
+__attribute__((noinline))
+void Throw() {
+ int local;
+ fprintf(stderr, "Throw: %p\n", &local);
+ throw 1;
+}
+
+__attribute__((noinline))
+void ThrowAndCatch() {
+ int local;
+ try {
+ Throw();
+ } catch(...) {
+ fprintf(stderr, "Catch: %p\n", &local);
+ }
+}
+
+void TestThrow() {
+ char x[32];
+ fprintf(stderr, "Before: %p poisoned: %d\n", &x,
+ __asan_address_is_poisoned(x + 32));
+ ThrowAndCatch();
+ fprintf(stderr, "After: %p poisoned: %d\n", &x,
+ __asan_address_is_poisoned(x + 32));
+ // FIXME: Invert this assertion once we fix
+ // https://code.google.com/p/address-sanitizer/issues/detail?id=258
+ assert(!__asan_address_is_poisoned(x + 32));
+}
+
+void TestThrowInline() {
+ char x[32];
+ fprintf(stderr, "Before: %p poisoned: %d\n", &x,
+ __asan_address_is_poisoned(x + 32));
+ try {
+ Throw();
+ } catch(...) {
+ fprintf(stderr, "Catch\n");
+ }
+ fprintf(stderr, "After: %p poisoned: %d\n", &x,
+ __asan_address_is_poisoned(x + 32));
+ // FIXME: Invert this assertion once we fix
+ // https://code.google.com/p/address-sanitizer/issues/detail?id=258
+ assert(!__asan_address_is_poisoned(x + 32));
+}
+
+static jmp_buf buf;
+
+void TestLongJmp() {
+ char x[32];
+ fprintf(stderr, "\nTestLongJmp\n");
+ fprintf(stderr, "Before: %p poisoned: %d\n", &x,
+ __asan_address_is_poisoned(x + 32));
+ if (0 == setjmp(buf))
+ longjmp(buf, 1);
+ fprintf(stderr, "After: %p poisoned: %d\n", &x,
+ __asan_address_is_poisoned(x + 32));
+ // FIXME: Invert this assertion once we fix
+ // https://code.google.com/p/address-sanitizer/issues/detail?id=258
+ assert(!__asan_address_is_poisoned(x + 32));
+}
+
+int main(int argc, char **argv) {
+ TestThrow();
+ TestThrowInline();
+ TestLongJmp();
+}
More information about the llvm-commits
mailing list