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