aboutsummaryrefslogtreecommitdiff
path: root/llvm/test/Transforms/Attributor/lowerheap.ll
blob: e87d47cea33a7bd5ecfd860c648ec1604ea69c59 (plain)
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
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --function-signature --check-attributes --check-globals
; RUN: opt -max-heap-to-stack-size=-1 -aa-pipeline=basic-aa -passes=attributor -attributor-manifest-internal  -attributor-annotate-decl-cs  -S < %s | FileCheck %s --check-prefixes=CHECK,TUNIT
; RUN: opt -max-heap-to-stack-size=-1 -aa-pipeline=basic-aa -passes=attributor-cgscc -attributor-manifest-internal  -attributor-annotate-decl-cs -S < %s | FileCheck %s --check-prefixes=CHECK,CGSCC

declare i64 @subfn(ptr) #0

declare noalias ptr @malloc(i64) allockind("alloc,uninitialized") allocsize(0) "alloc-family"="malloc"
declare noalias ptr @calloc(i64, i64) allockind("alloc,zeroed") allocsize(0,1) "alloc-family"="malloc"
declare void @free(ptr) allockind("free") "alloc-family"="malloc"

define i64 @f(i64 %len) {
; CHECK-LABEL: define {{[^@]+}}@f
; CHECK-SAME: (i64 [[LEN:%.*]]) {
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[MEM_H2S:%.*]] = alloca i8, i64 [[LEN]], align 1
; CHECK-NEXT:    [[RES:%.*]] = call i64 @subfn(ptr [[MEM_H2S]]) #[[ATTR5:[0-9]+]]
; CHECK-NEXT:    ret i64 [[RES]]
;
entry:
  %mem = call ptr @malloc(i64 %len)
  %res = call i64 @subfn(ptr %mem)
  call void @free(ptr %mem)
  ret i64 %res
}


define i64 @g(i64 %len) {
; CHECK-LABEL: define {{[^@]+}}@g
; CHECK-SAME: (i64 [[LEN:%.*]]) {
; CHECK-NEXT:  entry:
; CHECK-NEXT:    [[TMP0:%.*]] = mul i64 [[LEN]], 8
; CHECK-NEXT:    [[MEM_H2S:%.*]] = alloca i8, i64 [[TMP0]], align 1
; CHECK-NEXT:    call void @llvm.memset.p0.i64(ptr [[MEM_H2S]], i8 0, i64 [[TMP0]], i1 false)
; CHECK-NEXT:    [[RES:%.*]] = call i64 @subfn(ptr [[MEM_H2S]]) #[[ATTR5]]
; CHECK-NEXT:    ret i64 [[RES]]
;
entry:
  %mem = call ptr @calloc(i64 %len, i64 8)
  %res = call i64 @subfn(ptr %mem)
  call void @free(ptr %mem)
  ret i64 %res
}

attributes #0 = { nounwind willreturn }
;.
; CHECK: attributes #[[ATTR0:[0-9]+]] = { nounwind willreturn }
; CHECK: attributes #[[ATTR1:[0-9]+]] = { allockind("alloc,uninitialized") allocsize(0) "alloc-family"="malloc" }
; CHECK: attributes #[[ATTR2:[0-9]+]] = { allockind("alloc,zeroed") allocsize(0,1) "alloc-family"="malloc" }
; CHECK: attributes #[[ATTR3:[0-9]+]] = { allockind("free") "alloc-family"="malloc" }
; CHECK: attributes #[[ATTR4:[0-9]+]] = { nocallback nofree nounwind willreturn memory(argmem: write) }
; CHECK: attributes #[[ATTR5]] = { nounwind }
;.
;; NOTE: These prefixes are unused and the list is autogenerated. Do not add tests below this line:
; CGSCC: {{.*}}
; TUNIT: {{.*}}