llvm.org GIT mirror llvm / 0a52e95
[InstSimplify] guard against unreachable code (PR43218) This would crash: https://bugs.llvm.org/show_bug.cgi?id=43218 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@370911 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjay Patel a month ago
2 changed file(s) with 29 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
3333
3434 do {
3535 for (BasicBlock &BB : F) {
36 // Unreachable code can take on strange forms that we are not prepared to
37 // handle. For example, an instruction may have itself as an operand.
38 if (!SQ.DT->isReachableFromEntry(&BB))
39 continue;
40
3641 SmallVector DeadInstsInBB;
3742 for (Instruction &I : BB) {
3843 // The first time through the loop, ToSimplify is empty and we try to
8691 AU.addRequired();
8792 }
8893
89 /// runOnFunction - Remove instructions that simplify.
94 /// Remove instructions that simplify.
9095 bool runOnFunction(Function &F) override {
9196 if (skipFunction(F))
9297 return false;
6666 %vec = insertelement <8 x i8> %in, i8 %val, i32 %index
6767 ret <8 x i8> %vec
6868 }
69
70 ; The insert is in an unreachable block, so it is allowed to point to itself.
71 ; This would crash via stack overflow.
72
73 define void @PR43218() {
74 ; CHECK-LABEL: @PR43218(
75 ; CHECK-NEXT: end:
76 ; CHECK-NEXT: ret void
77 ; CHECK: unreachable_infloop:
78 ; CHECK-NEXT: [[EXTRACT:%.*]] = extractelement <2 x i64> [[BOGUS:%.*]], i32 0
79 ; CHECK-NEXT: [[T0:%.*]] = inttoptr i64 [[EXTRACT]] to i16****
80 ; CHECK-NEXT: [[BOGUS]] = insertelement <2 x i64> [[BOGUS]], i64 undef, i32 1
81 ; CHECK-NEXT: br label [[UNREACHABLE_INFLOOP:%.*]]
82 ;
83 end:
84 ret void
85
86 unreachable_infloop:
87 %extract = extractelement <2 x i64> %bogus, i32 0
88 %t0 = inttoptr i64 %extract to i16****
89 %bogus = insertelement <2 x i64> %bogus, i64 undef, i32 1
90 br label %unreachable_infloop
91 }