[llvm] 913b5d2 - [AsmPrinter] fix nullptr dereference for MBBs with hasAddressTaken property without BB
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 16 15:32:15 PDT 2021
Author: Afanasyev Ivan
Date: 2021-08-16T15:32:09-07:00
New Revision: 913b5d2f7af71b20be332064787baa1ec3f570c0
URL: https://github.com/llvm/llvm-project/commit/913b5d2f7af71b20be332064787baa1ec3f570c0
DIFF: https://github.com/llvm/llvm-project/commit/913b5d2f7af71b20be332064787baa1ec3f570c0.diff
LOG: [AsmPrinter] fix nullptr dereference for MBBs with hasAddressTaken property without BB
Basic block pointer is dereferenced unconditionally for MBBs with
hasAddressTaken property.
MBBs might have hasAddressTaken property without reference to BB.
Backend developers must assign fake BB to MBB to workaround this issue
and it should be fixed.
Reviewed By: rnk
Differential Revision: https://reviews.llvm.org/D108092
Added:
Modified:
llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 7171bfdd28e2d..4f48d007a1530 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -3270,21 +3270,21 @@ void AsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
// reference the block. It is possible that there is more than one label
// here, because multiple LLVM BB's may have been RAUW'd to this block after
// the references were generated.
+ const BasicBlock *BB = MBB.getBasicBlock();
if (MBB.hasAddressTaken()) {
- const BasicBlock *BB = MBB.getBasicBlock();
if (isVerbose())
OutStreamer->AddComment("Block address taken");
// MBBs can have their address taken as part of CodeGen without having
// their corresponding BB's address taken in IR
- if (BB->hasAddressTaken())
+ if (BB && BB->hasAddressTaken())
for (MCSymbol *Sym : MMI->getAddrLabelSymbolToEmit(BB))
OutStreamer->emitLabel(Sym);
}
// Print some verbose block comments.
if (isVerbose()) {
- if (const BasicBlock *BB = MBB.getBasicBlock()) {
+ if (BB) {
if (BB->hasName()) {
BB->printAsOperand(OutStreamer->GetCommentOS(),
/*PrintType=*/false, BB->getModule());
More information about the llvm-commits
mailing list