1 ; RUN: opt < %s -functionattrs -S | not grep {nocapture *%%q}
2 ; RUN: opt < %s -functionattrs -S | grep {nocapture *%%p} | count 6
3 @g = global i32* null ; <i32**> [#uses=1]
5 define i32* @c1(i32* %q) {
9 define void @c2(i32* %q) {
10 store i32* %q, i32** @g
14 define void @c3(i32* %q) {
15 call void @c2(i32* %q)
19 define i1 @c4(i32* %q, i32 %bitno) {
20 %tmp = ptrtoint i32* %q to i32
21 %tmp2 = lshr i32 %tmp, %bitno
22 %bit = trunc i32 %tmp2 to i1
23 br i1 %bit, label %l1, label %l0
25 ret i1 0 ; escaping value not caught by def-use chaining.
27 ret i1 1 ; escaping value not caught by def-use chaining.
30 @lookup_table = global [2 x i1] [ i1 0, i1 1 ]
32 define i1 @c5(i32* %q, i32 %bitno) {
33 %tmp = ptrtoint i32* %q to i32
34 %tmp2 = lshr i32 %tmp, %bitno
35 %bit = and i32 %tmp2, 1
36 ; subtle escape mechanism follows
37 %lookup = getelementptr [2 x i1]* @lookup_table, i32 0, i32 %bit
38 %val = load i1* %lookup
42 declare void @throw_if_bit_set(i8*, i8) readonly
43 define i1 @c6(i8* %q, i8 %bit) {
44 invoke void @throw_if_bit_set(i8* %q, i8 %bit)
45 to label %ret0 unwind label %ret1
52 define i1* @lookup_bit(i32* %q, i32 %bitno) readnone nounwind {
53 %tmp = ptrtoint i32* %q to i32
54 %tmp2 = lshr i32 %tmp, %bitno
55 %bit = and i32 %tmp2, 1
56 %lookup = getelementptr [2 x i1]* @lookup_table, i32 0, i32 %bit
60 define i1 @c7(i32* %q, i32 %bitno) {
61 %ptr = call i1* @lookup_bit(i32* %q, i32 %bitno)
67 define i32 @nc1(i32* %q, i32* %p, i1 %b) {
71 %x = phi i32* [ %p, %e ]
72 %y = phi i32* [ %q, %e ]
73 %tmp = bitcast i32* %x to i32* ; <i32*> [#uses=2]
74 %tmp2 = select i1 %b, i32* %tmp, i32* %y
75 %val = load i32* %tmp2 ; <i32> [#uses=1]
76 store i32 0, i32* %tmp
77 store i32* %y, i32** @g
81 define void @nc2(i32* %p, i32* %q) {
82 %1 = call i32 @nc1(i32* %q, i32* %p, i1 0) ; <i32> [#uses=0]
86 define void @nc3(void ()* %p) {
91 declare void @external(i8*) readonly nounwind
92 define void @nc4(i8* %p) {
93 call void @external(i8* %p)
97 define void @nc5(void (i8*)* %f, i8* %p) {
98 call void %f(i8* %p) readonly nounwind
99 call void %f(i8* nocapture %p)