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] 4 5 define i32* @c1(i32* %q) { 6 ret i32* %q 7 } 8 9 define void @c2(i32* %q) { 10 store i32* %q, i32** @g 11 ret void 12 } 13 14 define void @c3(i32* %q) { 15 call void @c2(i32* %q) 16 ret void 17 } 18 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 24 l0: 25 ret i1 0 ; escaping value not caught by def-use chaining. 26 l1: 27 ret i1 1 ; escaping value not caught by def-use chaining. 28 } 29 30 @lookup_table = global [2 x i1] [ i1 0, i1 1 ] 31 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 39 ret i1 %val 40 } 41 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 46 ret0: 47 ret i1 0 48 ret1: 49 %exn = landingpad {i8*, i32} personality i32 (...)* @__gxx_personality_v0 50 cleanup 51 ret i1 1 52 } 53 54 declare i32 @__gxx_personality_v0(...) 55 56 define i1* @lookup_bit(i32* %q, i32 %bitno) readnone nounwind { 57 %tmp = ptrtoint i32* %q to i32 58 %tmp2 = lshr i32 %tmp, %bitno 59 %bit = and i32 %tmp2, 1 60 %lookup = getelementptr [2 x i1]* @lookup_table, i32 0, i32 %bit 61 ret i1* %lookup 62 } 63 64 define i1 @c7(i32* %q, i32 %bitno) { 65 %ptr = call i1* @lookup_bit(i32* %q, i32 %bitno) 66 %val = load i1* %ptr 67 ret i1 %val 68 } 69 70 71 define i32 @nc1(i32* %q, i32* %p, i1 %b) { 72 e: 73 br label %l 74 l: 75 %x = phi i32* [ %p, %e ] 76 %y = phi i32* [ %q, %e ] 77 %tmp = bitcast i32* %x to i32* ; <i32*> [#uses=2] 78 %tmp2 = select i1 %b, i32* %tmp, i32* %y 79 %val = load i32* %tmp2 ; <i32> [#uses=1] 80 store i32 0, i32* %tmp 81 store i32* %y, i32** @g 82 ret i32 %val 83 } 84 85 define void @nc2(i32* %p, i32* %q) { 86 %1 = call i32 @nc1(i32* %q, i32* %p, i1 0) ; <i32> [#uses=0] 87 ret void 88 } 89 90 define void @nc3(void ()* %p) { 91 call void %p() 92 ret void 93 } 94 95 declare void @external(i8*) readonly nounwind 96 define void @nc4(i8* %p) { 97 call void @external(i8* %p) 98 ret void 99 } 100 101 define void @nc5(void (i8*)* %f, i8* %p) { 102 call void %f(i8* %p) readonly nounwind 103 call void %f(i8* nocapture %p) 104 ret void 105 } 106