1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm < %s | FileCheck %s 2 3 // Note: this test originally asserted that malloc/calloc/realloc got alignment 4 // attributes on their return pointer. However, that was reverted in 5 // https://reviews.llvm.org/D118804 and it now asserts that they do _NOT_ get 6 // align attributes. 7 8 typedef __SIZE_TYPE__ size_t; 9 10 void *malloc(size_t); 11 void *calloc(size_t, size_t); 12 void *realloc(void *, size_t); 13 void *aligned_alloc(size_t, size_t); 14 void *memalign(size_t, size_t); 15 16 void *malloc_test(size_t n) { 17 return malloc(n); 18 } 19 20 void *calloc_test(size_t n) { 21 return calloc(1, n); 22 } 23 24 void *realloc_test(void *p, size_t n) { 25 return realloc(p, n); 26 } 27 28 void *aligned_alloc_variable_test(size_t n, size_t a) { 29 return aligned_alloc(a, n); 30 } 31 32 void *memalign_variable_test(size_t n, size_t a) { 33 return memalign(a, n); 34 } 35 36 void *aligned_alloc_constant_test(size_t n) { 37 return aligned_alloc(8, n); 38 } 39 40 void *aligned_alloc_large_constant_test(size_t n) { 41 return aligned_alloc(4096, n); 42 } 43 44 void *memalign_large_constant_test(size_t n) { 45 return memalign(4096, n); 46 } 47 48 // CHECK-LABEL: @malloc_test 49 // CHECK: call i8* @malloc 50 51 // CHECK: declare i8* @malloc 52 53 // CHECK-LABEL: @calloc_test 54 // CHECK: call i8* @calloc 55 56 // CHECK: declare i8* @calloc 57 58 // CHECK-LABEL: @realloc_test 59 // CHECK: call i8* @realloc 60 61 // CHECK: declare i8* @realloc 62 63 // CHECK-LABEL: @aligned_alloc_variable_test 64 // CHECK: %[[ALLOCATED:.*]] = call i8* @aligned_alloc({{i32|i64}} noundef %[[ALIGN:.*]], {{i32|i64}} noundef %[[NBYTES:.*]]) 65 // CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[ALLOCATED]], {{i32|i64}} %[[ALIGN]]) ] 66 67 // CHECK: declare i8* @aligned_alloc 68 69 // CHECK-LABEL: @memalign_variable_test 70 // CHECK: %[[ALLOCATED:.*]] = call i8* @memalign({{i32|i64}} noundef %[[ALIGN:.*]], {{i32|i64}} noundef %[[NBYTES:.*]]) 71 // CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(i8* %[[ALLOCATED]], {{i32|i64}} %[[ALIGN]]) ] 72 73 // CHECK-LABEL: @aligned_alloc_constant_test 74 // CHECK: call align 8 i8* @aligned_alloc 75 76 // CHECK-LABEL: @aligned_alloc_large_constant_test 77 // CHECK: call align 4096 i8* @aligned_alloc 78 79 // CHECK-LABEL: @memalign_large_constant_test 80 // CHECK: align 4096 i8* @memalign 81 82