diff options
author | Kuba Brecka <kuba.brecka@gmail.com> | 2016-08-02 14:22:12 +0000 |
---|---|---|
committer | Kuba Brecka <kuba.brecka@gmail.com> | 2016-08-02 14:22:12 +0000 |
commit | a602a6d33501a813770698a7150b4113a430af47 (patch) | |
tree | d1994f82431ed89ec006a8c919e20c529111745e /test/tsan/Darwin | |
parent | 15712ac4dd8fa2f605ae1bebab233694b3d62383 (diff) | |
download | compiler-rt-a602a6d33501a813770698a7150b4113a430af47.tar.gz |
[tsan] Fix behavior of realloc(nullptr, 0) on Darwin
On Darwin, there are some apps that rely on realloc(nullptr, 0) returning a valid pointer. TSan currently returns nullptr in this case, let's fix it to avoid breaking binary compatibility.
Differential Revision: https://reviews.llvm.org/D22800
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@277458 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/tsan/Darwin')
-rw-r--r-- | test/tsan/Darwin/realloc-zero.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/tsan/Darwin/realloc-zero.cc b/test/tsan/Darwin/realloc-zero.cc new file mode 100644 index 000000000..c5053c3ee --- /dev/null +++ b/test/tsan/Darwin/realloc-zero.cc @@ -0,0 +1,20 @@ +// Test that realloc(nullptr, 0) return a non-NULL pointer. + +// RUN: %clang_tsan %s -o %t +// RUN: %run %t 2>&1 | FileCheck %s + +#include <malloc/malloc.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/mman.h> + +int main() { + void *p = realloc(nullptr, 0); + if (!p) { + abort(); + } + fprintf(stderr, "Okay.\n"); + return 0; +} + +// CHECK: Okay. |