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
malloc_test(size_t n)16 void *malloc_test(size_t n) {
17 return malloc(n);
18 }
19
calloc_test(size_t n)20 void *calloc_test(size_t n) {
21 return calloc(1, n);
22 }
23
realloc_test(void * p,size_t n)24 void *realloc_test(void *p, size_t n) {
25 return realloc(p, n);
26 }
27
aligned_alloc_variable_test(size_t n,size_t a)28 void *aligned_alloc_variable_test(size_t n, size_t a) {
29 return aligned_alloc(a, n);
30 }
31
memalign_variable_test(size_t n,size_t a)32 void *memalign_variable_test(size_t n, size_t a) {
33 return memalign(a, n);
34 }
35
aligned_alloc_constant_test(size_t n)36 void *aligned_alloc_constant_test(size_t n) {
37 return aligned_alloc(8, n);
38 }
39
aligned_alloc_large_constant_test(size_t n)40 void *aligned_alloc_large_constant_test(size_t n) {
41 return aligned_alloc(4096, n);
42 }
43
memalign_large_constant_test(size_t n)44 void *memalign_large_constant_test(size_t n) {
45 return memalign(4096, n);
46 }
47
48 // CHECK-LABEL: @malloc_test
49 // CHECK: call ptr @malloc
50
51 // CHECK: declare ptr @malloc
52
53 // CHECK-LABEL: @calloc_test
54 // CHECK: call ptr @calloc
55
56 // CHECK: declare ptr @calloc
57
58 // CHECK-LABEL: @realloc_test
59 // CHECK: call ptr @realloc
60
61 // CHECK: declare ptr @realloc
62
63 // CHECK-LABEL: @aligned_alloc_variable_test
64 // CHECK: %[[ALLOCATED:.*]] = call ptr @aligned_alloc({{i32|i64}} noundef %[[ALIGN:.*]], {{i32|i64}} noundef %[[NBYTES:.*]])
65 // CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr %[[ALLOCATED]], {{i32|i64}} %[[ALIGN]]) ]
66
67 // CHECK: declare ptr @aligned_alloc
68
69 // CHECK-LABEL: @memalign_variable_test
70 // CHECK: %[[ALLOCATED:.*]] = call ptr @memalign({{i32|i64}} noundef %[[ALIGN:.*]], {{i32|i64}} noundef %[[NBYTES:.*]])
71 // CHECK-NEXT: call void @llvm.assume(i1 true) [ "align"(ptr %[[ALLOCATED]], {{i32|i64}} %[[ALIGN]]) ]
72
73 // CHECK-LABEL: @aligned_alloc_constant_test
74 // CHECK: call align 8 ptr @aligned_alloc
75
76 // CHECK-LABEL: @aligned_alloc_large_constant_test
77 // CHECK: call align 4096 ptr @aligned_alloc
78
79 // CHECK-LABEL: @memalign_large_constant_test
80 // CHECK: align 4096 ptr @memalign
81
82