1 ; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s
2 ; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s
4 %struct.small = type { i8 }
6 @.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1
8 ; Address-of a structure taken in a function with a loop where
9 ; the alloca is an incoming value to a PHI node and a use of that PHI
10 ; node is also an incoming value.
11 ; Verify that the address-of analysis does not get stuck in infinite
12 ; recursion when chasing the alloca through the PHI nodes.
14 define i32 @foo(i32 %arg) nounwind uwtable safestack {
16 ; CHECK: __safestack_unsafe_stack_ptr
17 %tmp = alloca %struct.small*, align 8
18 %tmp1 = call i32 (...) @dummy(%struct.small** %tmp) nounwind
19 %tmp2 = load %struct.small*, %struct.small** %tmp, align 8
20 %tmp3 = ptrtoint %struct.small* %tmp2 to i64
21 %tmp4 = trunc i64 %tmp3 to i32
22 %tmp5 = icmp sgt i32 %tmp4, 0
23 br i1 %tmp5, label %bb6, label %bb21
25 bb6: ; preds = %bb17, %bb
26 %tmp7 = phi %struct.small* [ %tmp19, %bb17 ], [ %tmp2, %bb ]
27 %tmp8 = phi i64 [ %tmp20, %bb17 ], [ 1, %bb ]
28 %tmp9 = phi i32 [ %tmp14, %bb17 ], [ %tmp1, %bb ]
29 %tmp10 = getelementptr inbounds %struct.small, %struct.small* %tmp7, i64 0, i32 0
30 %tmp11 = load i8, i8* %tmp10, align 1
31 %tmp12 = icmp eq i8 %tmp11, 1
32 %tmp13 = add nsw i32 %tmp9, 8
33 %tmp14 = select i1 %tmp12, i32 %tmp13, i32 %tmp9
34 %tmp15 = trunc i64 %tmp8 to i32
35 %tmp16 = icmp eq i32 %tmp15, %tmp4
36 br i1 %tmp16, label %bb21, label %bb17
39 %tmp18 = getelementptr inbounds %struct.small*, %struct.small** %tmp, i64 %tmp8
40 %tmp19 = load %struct.small*, %struct.small** %tmp18, align 8
41 %tmp20 = add i64 %tmp8, 1
44 bb21: ; preds = %bb6, %bb
45 %tmp22 = phi i32 [ %tmp1, %bb ], [ %tmp14, %bb6 ]
46 %tmp23 = call i32 (...) @dummy(i32 %tmp22) nounwind
50 declare i32 @dummy(...)