Skip to content

Commit 96f372c

Browse files
[AsmWriter] Construct SlotTracker with the function
This patch teaches BasicBlock::print to construct an instance of SlotTracker with the containing function. Without this patch, we dump: *** IR Dump After LoopInstSimplifyPass *** ; Preheader: br label %1 ; Loop: <badref>: ; preds = %1, %0 br label %1 Note "<badref>" above. This happens because BasicBlock::print calls: SlotTracker SlotTable(this->getModule()); Note that this constructor does not add the contents of functions to the slot table. That is, basic blocks are left unnumbered. This patch fixes the problem by switching to: SlotTracker SlotTable(this->getParent()); which does add the contents of the Module and the function, this->getParent(), to the slot table. Differential Revision: https://reviews.llvm.org/D89567
1 parent 2564926 commit 96f372c

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

llvm/lib/IR/AsmWriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4417,7 +4417,7 @@ void Function::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW,
44174417
void BasicBlock::print(raw_ostream &ROS, AssemblyAnnotationWriter *AAW,
44184418
bool ShouldPreserveUseListOrder,
44194419
bool IsForDebug) const {
4420-
SlotTracker SlotTable(this->getModule());
4420+
SlotTracker SlotTable(this->getParent());
44214421
formatted_raw_ostream OS(ROS);
44224422
AssemblyWriter W(OS, SlotTable, this->getModule(), AAW,
44234423
IsForDebug,

llvm/test/Other/bb-badref.ll

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: opt -passes=loop-instsimplify -print-after-all -disable-output -S < %s 2>&1 | FileCheck %s
2+
3+
; loop-instsimplify dumps individual basic blocks as part of a loop,
4+
; not a function. Verify that the non-entry basic block is labeled as
5+
; "1", not "<badref>".
6+
7+
; CHECK-NOT: <badref>
8+
9+
define void @foo() {
10+
br label %1
11+
12+
1:
13+
br label %1
14+
}

0 commit comments

Comments
 (0)