diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1430,8 +1430,8 @@ } // Emit section containing BB address offsets and their metadata, when - // BB labels are requested for this function. - if (MF->hasBBLabels()) + // BB labels are requested for this function. Skip empty functions. + if (MF->hasBBLabels() && HasAnyRealCode) emitBBAddrMapSection(*MF); // Emit section containing stack size metadata. diff --git a/llvm/test/CodeGen/X86/basic-block-sections-labels-empty-function.ll b/llvm/test/CodeGen/X86/basic-block-sections-labels-empty-function.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/X86/basic-block-sections-labels-empty-function.ll @@ -0,0 +1,21 @@ +;; Verify that the BB address map is not emitted for empty functions. +; RUN: llc < %s -mtriple=x86_64 -basic-block-sections=labels | FileCheck %s + +define void @empty_func() { +entry: + unreachable +} +; CHECK: {{^ *}}.text{{$}} +; CHECK: empty_func: +; CHECK: .Lfunc_begin0: +; CHECK-NOT: .section .llvm_bb_addr_map + +define void @func() { +entry: + ret void +} + +; CHECK: func: +; CHECK: .Lfunc_begin1: +; CHECK: .section .llvm_bb_addr_map,"o",@llvm_bb_addr_map,.text{{$}} +; CHECK: .quad .Lfunc_begin1