[Reland][Runtimes] Merge 'compile_commands.json' files from runtimes build (#116303)
[llvm-project.git] / clang / test / CodeGen / alloc-fns-alignment.c
blob07261dfbaf5dd03a132c73194d97318f73ab432d
1 // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm < %s | FileCheck %s
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.
8 typedef __SIZE_TYPE__ size_t;
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);
16 void *malloc_test(size_t n) {
17 return malloc(n);
20 void *calloc_test(size_t n) {
21 return calloc(1, n);
24 void *realloc_test(void *p, size_t n) {
25 return realloc(p, n);
28 void *aligned_alloc_variable_test(size_t n, size_t a) {
29 return aligned_alloc(a, n);
32 void *memalign_variable_test(size_t n, size_t a) {
33 return memalign(a, n);
36 void *aligned_alloc_constant_test(size_t n) {
37 return aligned_alloc(8, n);
40 void *aligned_alloc_large_constant_test(size_t n) {
41 return aligned_alloc(4096, n);
44 void *memalign_large_constant_test(size_t n) {
45 return memalign(4096, n);
48 // CHECK-LABEL: @malloc_test
49 // CHECK: call ptr @malloc
51 // CHECK: declare ptr @malloc
53 // CHECK-LABEL: @calloc_test
54 // CHECK: call ptr @calloc
56 // CHECK: declare ptr @calloc
58 // CHECK-LABEL: @realloc_test
59 // CHECK: call ptr @realloc
61 // CHECK: declare ptr @realloc
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]]) ]
67 // CHECK: declare ptr @aligned_alloc
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]]) ]
73 // CHECK-LABEL: @aligned_alloc_constant_test
74 // CHECK: call align 8 ptr @aligned_alloc
76 // CHECK-LABEL: @aligned_alloc_large_constant_test
77 // CHECK: call align 4096 ptr @aligned_alloc
79 // CHECK-LABEL: @memalign_large_constant_test
80 // CHECK: align 4096 ptr @memalign