crash.ll 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. ; RUN: opt -gvn -disable-output < %s
  2. ; PR5631
  3. target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
  4. target triple = "x86_64-apple-darwin10.0"
  5. define i32* @test1(i8* %name, i32 %namelen, i32* %o, i32 %expected_type) nounwind ssp {
  6. entry:
  7. br i1 undef, label %if.end13, label %while.body.preheader
  8. if.end13: ; preds = %if.then6
  9. br label %while.body.preheader
  10. while.body.preheader: ; preds = %if.end13, %if.end
  11. br label %while.body
  12. while.body: ; preds = %while.body.backedge, %while.body.preheader
  13. %o.addr.0 = phi i32* [ undef, %while.body.preheader ], [ %o.addr.0.be, %while.body.backedge ] ; <i32*> [#uses=2]
  14. br i1 false, label %return.loopexit, label %lor.lhs.false
  15. lor.lhs.false: ; preds = %while.body
  16. %tmp20 = bitcast i32* %o.addr.0 to i32* ; <i32*> [#uses=1]
  17. %tmp22 = load i32, i32* %tmp20 ; <i32> [#uses=0]
  18. br i1 undef, label %land.lhs.true24, label %if.end31
  19. land.lhs.true24: ; preds = %lor.lhs.false
  20. %call28 = call i32* @parse_object(i8* undef) nounwind ; <i32*> [#uses=0]
  21. br i1 undef, label %return.loopexit, label %if.end31
  22. if.end31: ; preds = %land.lhs.true24, %lor.lhs.false
  23. br i1 undef, label %return.loopexit, label %if.end41
  24. if.end41: ; preds = %if.end31
  25. %tmp43 = bitcast i32* %o.addr.0 to i32* ; <i32*> [#uses=1]
  26. %tmp45 = load i32, i32* %tmp43 ; <i32> [#uses=0]
  27. br i1 undef, label %if.then50, label %if.else
  28. if.then50: ; preds = %if.end41
  29. %tmp53 = load i32*, i32** undef ; <i32*> [#uses=1]
  30. br label %while.body.backedge
  31. if.else: ; preds = %if.end41
  32. br i1 undef, label %if.then62, label %if.else67
  33. if.then62: ; preds = %if.else
  34. br label %while.body.backedge
  35. while.body.backedge: ; preds = %if.then62, %if.then50
  36. %o.addr.0.be = phi i32* [ %tmp53, %if.then50 ], [ undef, %if.then62 ] ; <i32*> [#uses=1]
  37. br label %while.body
  38. if.else67: ; preds = %if.else
  39. ret i32* null
  40. return.loopexit: ; preds = %if.end31, %land.lhs.true24, %while.body
  41. ret i32* undef
  42. }
  43. declare i32* @parse_object(i8*)
  44. %struct.attribute_spec = type { i8*, i32, i32, i8, i8, i8 }
  45. @attribute_tables = external global [4 x %struct.attribute_spec*] ; <[4 x %struct.attribute_spec*]*> [#uses=2]
  46. define void @test2() nounwind {
  47. entry:
  48. br label %bb69.i
  49. bb69.i: ; preds = %bb57.i.preheader
  50. %tmp4 = getelementptr inbounds [4 x %struct.attribute_spec*], [4 x %struct.attribute_spec*]* @attribute_tables, i32 0, i32 undef ; <%struct.attribute_spec**> [#uses=1]
  51. %tmp3 = load %struct.attribute_spec*, %struct.attribute_spec** %tmp4, align 4 ; <%struct.attribute_spec*> [#uses=1]
  52. br label %bb65.i
  53. bb65.i: ; preds = %bb65.i.preheader, %bb64.i
  54. %storemerge6.i = phi i32 [ 1, %bb64.i ], [ 0, %bb69.i ] ; <i32> [#uses=3]
  55. %scevgep14 = getelementptr inbounds %struct.attribute_spec, %struct.attribute_spec* %tmp3, i32 %storemerge6.i, i32 0 ; <i8**> [#uses=1]
  56. %tmp2 = load i8*, i8** %scevgep14, align 4 ; <i8*> [#uses=0]
  57. %tmp = load %struct.attribute_spec*, %struct.attribute_spec** %tmp4, align 4 ; <%struct.attribute_spec*> [#uses=1]
  58. %scevgep1516 = getelementptr inbounds %struct.attribute_spec, %struct.attribute_spec* %tmp, i32 %storemerge6.i, i32 0 ; <i8**> [#uses=0]
  59. unreachable
  60. bb64.i: ; Unreachable
  61. br label %bb65.i
  62. bb66.i: ; Unreachable
  63. br label %bb69.i
  64. }
  65. ; rdar://7438974
  66. @g = external global i64, align 8
  67. define i32* @test3() {
  68. do.end17.i:
  69. %tmp18.i = load i7*, i7** undef
  70. %tmp1 = bitcast i7* %tmp18.i to i8*
  71. br i1 undef, label %do.body36.i, label %if.then21.i
  72. if.then21.i:
  73. %tmp2 = bitcast i7* %tmp18.i to i8*
  74. ret i32* undef
  75. do.body36.i:
  76. %ivar38.i = load i64, i64* @g
  77. %tmp3 = bitcast i7* %tmp18.i to i8*
  78. %add.ptr39.sum.i = add i64 %ivar38.i, 8
  79. %tmp40.i = getelementptr inbounds i8, i8* %tmp3, i64 %add.ptr39.sum.i
  80. %tmp4 = bitcast i8* %tmp40.i to i64*
  81. %tmp41.i = load i64, i64* %tmp4
  82. br i1 undef, label %if.then48.i, label %do.body57.i
  83. if.then48.i:
  84. %call54.i = call i32 @foo2()
  85. br label %do.body57.i
  86. do.body57.i:
  87. %tmp58.i = load i7*, i7** undef
  88. %ivar59.i = load i64, i64* @g
  89. %tmp5 = bitcast i7* %tmp58.i to i8*
  90. %add.ptr65.sum.i = add i64 %ivar59.i, 8
  91. %tmp66.i = getelementptr inbounds i8, i8* %tmp5, i64 %add.ptr65.sum.i
  92. %tmp6 = bitcast i8* %tmp66.i to i64*
  93. %tmp67.i = load i64, i64* %tmp6
  94. ret i32* undef
  95. }
  96. declare i32 @foo2()
  97. define i32 @test4() {
  98. entry:
  99. ret i32 0
  100. dead:
  101. %P2 = getelementptr i32, i32 *%P2, i32 52
  102. %Q2 = getelementptr i32, i32 *%Q2, i32 52
  103. store i32 4, i32* %P2
  104. %A = load i32, i32* %Q2
  105. br i1 true, label %dead, label %dead2
  106. dead2:
  107. ret i32 %A
  108. }
  109. ; PR9841
  110. define fastcc i8 @test5(i8* %P) nounwind {
  111. entry:
  112. %0 = load i8, i8* %P, align 2
  113. %Q = getelementptr i8, i8* %P, i32 1
  114. %1 = load i8, i8* %Q, align 1
  115. ret i8 %1
  116. }
  117. ; Test that a GEP in an unreachable block with the following form doesn't crash
  118. ; GVN:
  119. ;
  120. ; %x = gep %some.type %x, ...
  121. %struct.type = type { i64, i32, i32 }
  122. define fastcc void @func() nounwind uwtable ssp align 2 {
  123. entry:
  124. br label %reachable.bb
  125. ;; Unreachable code.
  126. unreachable.bb:
  127. %gep.val = getelementptr inbounds %struct.type, %struct.type* %gep.val, i64 1
  128. br i1 undef, label %u2.bb, label %u1.bb
  129. u1.bb:
  130. %tmp1 = getelementptr inbounds %struct.type, %struct.type* %gep.val, i64 0, i32 0
  131. store i64 -1, i64* %tmp1, align 8
  132. br label %unreachable.bb
  133. u2.bb:
  134. %0 = load i32, i32* undef, align 4
  135. %conv.i.i.i.i.i = zext i32 %0 to i64
  136. br label %u2.bb
  137. ;; Reachable code.
  138. reachable.bb:
  139. br label %r1.bb
  140. r1.bb:
  141. br label %u2.bb
  142. }