[llvm] Instruction: avoid crash in getStableDebugLoc when `this` isn't a DbgInfoIntrinsic (PR #66266)
Augie Fackler via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 13 11:08:24 PDT 2023
https://github.com/durin42 created https://github.com/llvm/llvm-project/pull/66266:
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.
>From dcd07f34c350f44acc669987e3ed819ad7209ae5 Mon Sep 17 00:00:00 2001
From: Augie Fackler <augie at google.com>
Date: Wed, 13 Sep 2023 14:04:10 -0400
Subject: [PATCH] Instruction: avoid crash in getStableDebugLoc when `this`
isn't a DbgInfoIntrinsic
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.
---
llvm/lib/IR/Instruction.cpp | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
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();
}
More information about the llvm-commits
mailing list