[compiler-rt] r190135 - [tsan] make calloc crash instead of returning 0 on overflow (controlled by the allocator_may_return_null flag)

Bill Wendling wendling at apple.com
Mon Sep 9 11:23:27 PDT 2013


On Sep 6, 2013, at 4:04 AM, Kostya Serebryany <kcc at google.com> wrote:

> Author: kcc
> Date: Fri Sep  6 06:04:14 2013
> New Revision: 190135
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=190135&view=rev
> Log:
> [tsan] make calloc crash instead of returning 0 on overflow (controlled by the allocator_may_return_null flag)
> 
> Added:
>    compiler-rt/trunk/lib/tsan/lit_tests/allocator_returns_null.cc
> Modified:
>    compiler-rt/trunk/lib/tsan/lit_tests/malloc_overflow.cc
>    compiler-rt/trunk/lib/tsan/rtl/tsan_interceptors.cc
>    compiler-rt/trunk/lib/tsan/rtl/tsan_mman.cc
>    compiler-rt/trunk/lib/tsan/tests/unit/tsan_mman_test.cc
> 
> Added: compiler-rt/trunk/lib/tsan/lit_tests/allocator_returns_null.cc
> URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/allocator_returns_null.cc?rev=190135&view=auto
> ==============================================================================
> --- compiler-rt/trunk/lib/tsan/lit_tests/allocator_returns_null.cc (added)
> +++ compiler-rt/trunk/lib/tsan/lit_tests/allocator_returns_null.cc Fri Sep  6 06:04:14 2013
> @@ -0,0 +1,64 @@
> +// Test the behavior of malloc/calloc/realloc when the allocation size is huge.
> +// By default (allocator_may_return_null=0) the process shoudl crash.
> +// With allocator_may_return_null=1 the allocator should return 0.
> +//
> +// RUN: %clangxx_tsan -O0 %s -o %t
> +// RUN: not %t malloc 2>&1 | FileCheck %s --check-prefix=CHECK-mCRASH
> +// RUN: TSAN_OPTIONS=allocator_may_return_null=0 not %t malloc 2>&1 | FileCheck %s --check-prefix=CHECK-mCRASH
> +// RUN: TSAN_OPTIONS=allocator_may_return_null=0 not %t calloc 2>&1 | FileCheck %s --check-prefix=CHECK-cCRASH
> +// RUN: TSAN_OPTIONS=allocator_may_return_null=0 not %t calloc-overflow 2>&1 | FileCheck %s --check-prefix=CHECK-coCRASH
> +// RUN: TSAN_OPTIONS=allocator_may_return_null=0 not %t realloc 2>&1 | FileCheck %s --check-prefix=CHECK-rCRASH
> +// RUN: TSAN_OPTIONS=allocator_may_return_null=0 not %t realloc-after-malloc 2>&1 | FileCheck %s --check-prefix=CHECK-mrCRASH
> +

A small nit. For me, the prefixes you have here are a bit hard to read. Might I suggest something like these?

	M-CRASH
	C-CRASH
	CO-CRASH
	R-CRASH
	MR-CRASH

Feel free to not do that. It's only a suggestion. :-)

-bw



More information about the llvm-commits mailing list