2013-09-06 19:04:14 +08:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t
|
2015-11-20 01:28:46 +08:00
|
|
|
// RUN: %env_tsan_opts=allocator_may_return_null=1 %run %t 2>&1 | FileCheck %s
|
2013-03-23 01:06:22 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
void *p = malloc((size_t)-1);
|
|
|
|
if (p != 0)
|
2016-04-15 20:34:00 +08:00
|
|
|
fprintf(stderr, "FAIL malloc(-1) = %p\n", p);
|
2013-03-23 01:06:22 +08:00
|
|
|
p = malloc((size_t)-1 / 2);
|
|
|
|
if (p != 0)
|
2016-04-15 20:34:00 +08:00
|
|
|
fprintf(stderr, "FAIL malloc(-1/2) = %p\n", p);
|
2013-03-23 01:06:22 +08:00
|
|
|
p = calloc((size_t)-1, (size_t)-1);
|
|
|
|
if (p != 0)
|
2016-04-15 20:34:00 +08:00
|
|
|
fprintf(stderr, "FAIL calloc(-1, -1) = %p\n", p);
|
2013-03-23 01:06:22 +08:00
|
|
|
p = calloc((size_t)-1 / 2, (size_t)-1 / 2);
|
|
|
|
if (p != 0)
|
2016-04-15 20:34:00 +08:00
|
|
|
fprintf(stderr, "FAIL calloc(-1/2, -1/2) = %p\n", p);
|
|
|
|
fprintf(stderr, "OK\n");
|
2013-03-23 01:06:22 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// CHECK-NOT: FAIL
|
|
|
|
// CHECK-NOT: failed to allocate
|