[llvm] Instruction: avoid crash in getStableDebugLoc when `this` isn't a DbgInfoIntrinsic (PR #66266)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 13 11:09:26 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
<details>
<summary>Changes</summary>
This fixes a crash in `rustc` that was triggered by https://reviews.llvm.org/D159485 (aka
llvm/llvm-project at 1ce1732f82aec29ec27d6de58153d516bca1d633). I can't claim to fully understand the fix - my efforts at debugging were stymied by the crashing lines getting optimzed too well, and when I disabled optimizations the crash managed to go away and be replaced by something more confusing. @krasimirgg wrote this and I tested it, and he asked me to submit it for review.
--
Full diff: https://github.com/llvm/llvm-project/pull/66266.diff
1 Files Affected:
- (modified) llvm/lib/IR/Instruction.cpp (+5-2)
<pre>
diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index 6b0348f8f691fd4..37cce7729741745 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/lib/IR/Instruction.cpp
@@ -886,8 +886,11 @@ Instruction::getPrevNonDebugInstruction(bool SkipPseudoOp) const {
}
const DebugLoc &Instruction::getStableDebugLoc() const {
- if (isa<DbgInfoIntrinsic>(this))
- return getNextNonDebugInstruction()->getDebugLoc();
+ if (isa<DbgInfoIntrinsic>(this)) {
+ const Instruction* next = getNextNonDebugInstruction();
+ if (next)
+ return next->getDebugLoc();
+ }
return getDebugLoc();
}
</pre>
</details>
https://github.com/llvm/llvm-project/pull/66266
More information about the llvm-commits
mailing list