Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | // RUN: %clangxx_tsan -O1 %s -o %t |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 2 | // RUN: %env_tsan_opts=allocator_may_return_null=1 %run %t 2>&1 | FileCheck %s |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 3 | #include <stdio.h> |
| 4 | #include <stdlib.h> |
| 5 | |
| 6 | int main() { |
| 7 | void *p = malloc((size_t)-1); |
| 8 | if (p != 0) |
| 9 | printf("FAIL malloc(-1) = %p\n", p); |
| 10 | p = malloc((size_t)-1 / 2); |
| 11 | if (p != 0) |
| 12 | printf("FAIL malloc(-1/2) = %p\n", p); |
| 13 | p = calloc((size_t)-1, (size_t)-1); |
| 14 | if (p != 0) |
| 15 | printf("FAIL calloc(-1, -1) = %p\n", p); |
| 16 | p = calloc((size_t)-1 / 2, (size_t)-1 / 2); |
| 17 | if (p != 0) |
| 18 | printf("FAIL calloc(-1/2, -1/2) = %p\n", p); |
| 19 | printf("OK\n"); |
| 20 | } |
| 21 | |
| 22 | // CHECK-NOT: FAIL |
| 23 | // CHECK-NOT: failed to allocate |