2
0

phi-cycle.ll 2.0 KB

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