[PATCH] D138072: [llvm-reduce] Do not crash when accessing landingpads of invokes.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 15 15:59:40 PST 2022
fhahn created this revision.
fhahn added reviewers: arsenm, aeubanks.
Herald added a project: All.
fhahn requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.
During basic-block reductions, landing pads can get removed. If there
are multiple invokes that share the same landing pad,
Invoke->getLandingPadInst() for the second invoke will crash because
IR is now temporarily invalid, breaking the assumption that a landing
pad instruction must exist.
To avoid crashing just look for the landing pad manually and account for
the possibility that it may not exist.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D138072
Files:
llvm/test/tools/llvm-reduce/invoke-with-missing-landingpad.ll
llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
Index: llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
+++ llvm/tools/llvm-reduce/deltas/ReduceBasicBlocks.cpp
@@ -47,9 +47,11 @@
bool IsBranch = isa<BranchInst>(Term);
if (InvokeInst *Invoke = dyn_cast<InvokeInst>(Term)) {
- LandingPadInst *LP = Invoke->getLandingPadInst();
- LP->replaceAllUsesWith(getDefaultValue(LP->getType()));
- LP->eraseFromParent();
+ if (LandingPadInst *LP = dyn_cast_or_null<LandingPadInst>(
+ Invoke->getUnwindDest()->getFirstNonPHI())) {
+ LP->replaceAllUsesWith(getDefaultValue(LP->getType()));
+ LP->eraseFromParent();
+ }
IsBranch = true;
}
Index: llvm/test/tools/llvm-reduce/invoke-with-missing-landingpad.ll
===================================================================
--- /dev/null
+++ llvm/test/tools/llvm-reduce/invoke-with-missing-landingpad.ll
@@ -0,0 +1,37 @@
+; RUN: llvm-reduce --delta-passes=basic-blocks --test FileCheck --test-arg --check-prefixes=CHECK-INTERESTINGNESS --test-arg %s --test-arg --input-file %s -o %t
+; RUN: FileCheck <%t %s
+
+; CHECK-INTERESTINGNESS: call void @foo()
+
+; CHECK: define void @test() personality ptr null {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: br label %cont
+; CHECK-EMPTY:
+; CHECK-NEXT: cont:
+; CHECK-NEXT: br label %exit
+; CHECK-EMPTY:
+; CHECK-NEXT: exit:
+; CHECK-NEXT: call void @foo()
+; CHECK-NEXT: ret void
+; CHECK-NEXT: }
+
+define void @test() personality ptr null {
+entry:
+ invoke void @foo()
+ to label %cont unwind label %lpad
+
+cont:
+ invoke void @foo()
+ to label %exit unwind label %lpad
+
+lpad:
+ %0 = landingpad { ptr, i32 }
+ cleanup
+ ret void
+
+exit:
+ call void @foo()
+ ret void
+}
+
+declare void @foo()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138072.475619.patch
Type: text/x-patch
Size: 1850 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221115/b65b5449/attachment.bin>
More information about the llvm-commits
mailing list