brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 07261df Raw
82 lines · c
1// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm < %s | FileCheck %s2 3// Note: this test originally asserted that malloc/calloc/realloc got alignment4// attributes on their return pointer. However, that was reverted in5// https://reviews.llvm.org/D118804 and it now asserts that they do _NOT_ get6// align attributes.7 8typedef __SIZE_TYPE__ size_t;9 10void *malloc(size_t);11void *calloc(size_t, size_t);12void *realloc(void *, size_t);13void *aligned_alloc(size_t, size_t);14void *memalign(size_t, size_t);15 16void *malloc_test(size_t n) {17  return malloc(n);18}19 20void *calloc_test(size_t n) {21  return calloc(1, n);22}23 24void *realloc_test(void *p, size_t n) {25  return realloc(p, n);26}27 28void *aligned_alloc_variable_test(size_t n, size_t a) {29  return aligned_alloc(a, n);30}31 32void *memalign_variable_test(size_t n, size_t a) {33  return memalign(a, n);34}35 36void *aligned_alloc_constant_test(size_t n) {37  return aligned_alloc(8, n);38}39 40void *aligned_alloc_large_constant_test(size_t n) {41  return aligned_alloc(4096, n);42}43 44void *memalign_large_constant_test(size_t n) {45  return memalign(4096, n);46}47 48// CHECK-LABEL: @malloc_test49// CHECK: call ptr @malloc50 51// CHECK: declare ptr @malloc52 53// CHECK-LABEL: @calloc_test54// CHECK: call ptr @calloc55 56// CHECK: declare ptr @calloc57 58// CHECK-LABEL: @realloc_test59// CHECK: call ptr @realloc60 61// CHECK: declare ptr @realloc62 63// CHECK-LABEL: @aligned_alloc_variable_test64// 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_alloc68 69// CHECK-LABEL: @memalign_variable_test70// 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_test74// CHECK: call align 8 ptr @aligned_alloc75 76// CHECK-LABEL: @aligned_alloc_large_constant_test77// CHECK: call align 4096 ptr @aligned_alloc78 79// CHECK-LABEL: @memalign_large_constant_test80// CHECK: align 4096 ptr @memalign81 82