Skip to content

Commit 913b5d2

Browse files
ivafanasrnk
authored andcommitted
[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
1 parent 83457d3 commit 913b5d2

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3270,21 +3270,21 @@ void AsmPrinter::emitBasicBlockStart(const MachineBasicBlock &MBB) {
32703270
// reference the block. It is possible that there is more than one label
32713271
// here, because multiple LLVM BB's may have been RAUW'd to this block after
32723272
// the references were generated.
3273+
const BasicBlock *BB = MBB.getBasicBlock();
32733274
if (MBB.hasAddressTaken()) {
3274-
const BasicBlock *BB = MBB.getBasicBlock();
32753275
if (isVerbose())
32763276
OutStreamer->AddComment("Block address taken");
32773277

32783278
// MBBs can have their address taken as part of CodeGen without having
32793279
// their corresponding BB's address taken in IR
3280-
if (BB->hasAddressTaken())
3280+
if (BB && BB->hasAddressTaken())
32813281
for (MCSymbol *Sym : MMI->getAddrLabelSymbolToEmit(BB))
32823282
OutStreamer->emitLabel(Sym);
32833283
}
32843284

32853285
// Print some verbose block comments.
32863286
if (isVerbose()) {
3287-
if (const BasicBlock *BB = MBB.getBasicBlock()) {
3287+
if (BB) {
32883288
if (BB->hasName()) {
32893289
BB->printAsOperand(OutStreamer->GetCommentOS(),
32903290
/*PrintType=*/false, BB->getModule());

0 commit comments

Comments
 (0)