1 ; RUN: opt < %s -basicaa -functionattrs -rpo-functionattrs -S | FileCheck %s --check-prefixes=CHECK,BOTH
2 ; RUN: opt < %s -aa-pipeline=basic-aa -passes='cgscc(function-attrs),rpo-functionattrs' -S | FileCheck %s --check-prefixes=CHECK,BOTH
3 ; RUN: opt -passes=attributor --attributor-disable=false -attributor-max-iterations-verify -attributor-max-iterations=4 -S < %s | FileCheck %s --check-prefixes=ATTRIBUTOR,BOTH
5 ; CHECK: Function Attrs
6 ; CHECK-SAME: norecurse nounwind readnone
7 ; ATTRIBUTOR: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
8 ; BOTH-NEXT: define i32 @leaf()
13 ; BOTH: Function Attrs
16 ; BOTH-NEXT: define i32 @self_rec()
17 define i32 @self_rec() {
18 %a = call i32 @self_rec()
22 ; BOTH: Function Attrs
25 ; BOTH-NEXT: define i32 @indirect_rec()
26 define i32 @indirect_rec() {
27 %a = call i32 @indirect_rec2()
30 ; BOTH: Function Attrs
33 ; BOTH-NEXT: define i32 @indirect_rec2()
34 define i32 @indirect_rec2() {
35 %a = call i32 @indirect_rec()
39 ; BOTH: Function Attrs
42 ; BOTH-NEXT: define i32 @extern()
43 define i32 @extern() {
48 ; BOTH: Function Attrs
49 ; BOTH-NEXT: declare i32 @k()
50 declare i32 @k() readnone
52 ; BOTH: Function Attrs
53 ; CHECK-SAME: nounwind
55 ; CHECK-NEXT: define void @intrinsic(i8* nocapture %dest, i8* nocapture readonly %src, i32 %len)
56 ; ATTRIBUTOR-NEXT: define void @intrinsic(i8* nocapture writeonly %dest, i8* nocapture readonly %src, i32 %len)
57 define void @intrinsic(i8* %dest, i8* %src, i32 %len) {
58 call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 %len, i1 false)
62 ; BOTH: Function Attrs
63 ; BOTH-NEXT: declare void @llvm.memcpy.p0i8.p0i8.i32
64 declare void @llvm.memcpy.p0i8.p0i8.i32(i8*, i8*, i32, i1)
66 ; BOTH: Function Attrs
67 ; CHECK-SAME: norecurse readnone
68 ; FIXME: missing "norecurse"
69 ; ATTRIBUTOR-SAME: nosync readnone
70 ; CHECK-NEXT: define internal i32 @called_by_norecurse()
71 define internal i32 @called_by_norecurse() {
75 ; BOTH: Function Attrs
76 ; BOTH-NEXT: define void @m()
77 define void @m() norecurse {
78 %a = call i32 @called_by_norecurse()
82 ; BOTH: Function Attrs
83 ; CHECK-SAME: norecurse readnone
84 ; FIXME: missing "norecurse"
85 ; ATTRIBUTOR-SAME: nosync
86 ; CHECK-NEXT: define internal i32 @called_by_norecurse_indirectly()
87 define internal i32 @called_by_norecurse_indirectly() {
91 define internal void @o() {
92 %a = call i32 @called_by_norecurse_indirectly()
95 define void @p() norecurse {
100 ; ATTRIBUTOR: Function Attrs: nofree nosync nounwind
101 ; ATTRIBUTOR-NEXT: define void @f(i32 %x)
102 define void @f(i32 %x) {
104 %x.addr = alloca i32, align 4
105 store i32 %x, i32* %x.addr, align 4
106 %0 = load i32, i32* %x.addr, align 4
107 %tobool = icmp ne i32 %0, 0
108 br i1 %tobool, label %if.then, label %if.end
111 call void @g() norecurse
118 ; BOTH: define void @g()
119 define void @g() norecurse {
125 ; ATTRIBUTOR-NOT: Function Attrs
126 ; ATTRIBUTOR: define linkonce_odr i32 @leaf_redefinable()
127 define linkonce_odr i32 @leaf_redefinable() {
131 ; Call through a function pointer
132 ; ATTRIBUTOR-NOT: Function Attrs
133 ; ATTRIBUTOR: define i32 @eval_func1(i32 (i32)* nocapture nonnull %0, i32 %1)
134 define i32 @eval_func1(i32 (i32)* , i32) local_unnamed_addr {
135 %3 = tail call i32 %0(i32 %1) #2
139 ; ATTRIBUTOR-NOT: Function Attrs
140 ; ATTRIBUTOR: define i32 @eval_func2(i32 (i32)* nocapture %0, i32 %1)
141 define i32 @eval_func2(i32 (i32)* , i32) local_unnamed_addr "null-pointer-is-valid"="true"{
142 %3 = tail call i32 %0(i32 %1) #2
146 declare void @unknown()
147 ; Call an unknown function in a dead block.
148 ; ATTRIBUTOR: Function Attrs: nofree norecurse nosync nounwind readnone willreturn
149 ; ATTRIBUTOR: define i32 @call_unknown_in_dead_block()
150 define i32 @call_unknown_in_dead_block() local_unnamed_addr {
153 tail call void @unknown()