1 // RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s 2 #include <stdio.h> 3 #include <stdlib.h> 4 5 int main() { 6 void *p = malloc((size_t)-1); 7 if (p != 0) 8 printf("FAIL malloc(-1) = %p\n", p); 9 p = malloc((size_t)-1 / 2); 10 if (p != 0) 11 printf("FAIL malloc(-1/2) = %p\n", p); 12 p = calloc((size_t)-1, (size_t)-1); 13 if (p != 0) 14 printf("FAIL calloc(-1, -1) = %p\n", p); 15 p = calloc((size_t)-1 / 2, (size_t)-1 / 2); 16 if (p != 0) 17 printf("FAIL calloc(-1/2, -1/2) = %p\n", p); 18 printf("OK\n"); 19 } 20 21 // CHECK-NOT: FAIL 22 // CHECK-NOT: failed to allocate 23