diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -2416,15 +2416,16 @@ MCContext &Ctx = getContext(); - // FIXME: use section end symbol as end of the Section. We need to consider - // the explicit sections and -ffunction-sections when we try to generate or - // find section end symbol for the Section. - MCSection *TextSection = Ctx.getObjectFileInfo()->getTextSection(); - assert(TextSection->hasEnded() && ".text section is not end!"); + // When EndLabel is null (from AsmParser), conservatively Text section end + // symbol as EndLabel. + if (!EndLabel) { + MCSection *TextSection = Ctx.getObjectFileInfo()->getTextSection(); + assert(TextSection->hasEnded() && ".text section is not end!"); - MCSymbol *SectionEnd = TextSection->getEndSymbol(Ctx); + EndLabel = TextSection->getEndSymbol(Ctx); + } const MCAsmInfo *AsmInfo = Ctx.getAsmInfo(); - emitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, SectionEnd, + emitDwarfAdvanceLineAddr(INT64_MAX, LastLabel, EndLabel, AsmInfo->getCodePointerSize()); } diff --git a/llvm/test/DebugInfo/XCOFF/empty.ll b/llvm/test/DebugInfo/XCOFF/empty.ll --- a/llvm/test/DebugInfo/XCOFF/empty.ll +++ b/llvm/test/DebugInfo/XCOFF/empty.ll @@ -225,10 +225,10 @@ ; ASM32-NEXT: .byte 3 # Advance line 1 ; ASM32-NEXT: .byte 1 ; ASM32-NEXT: .byte 1 -; ASM32-NEXT: .byte 0 # Set address to L..sec_end0 +; ASM32-NEXT: .byte 0 # Set address to L..func_end0 ; ASM32-NEXT: .byte 5 ; ASM32-NEXT: .byte 2 -; ASM32-NEXT: .vbyte 4, L..sec_end0 +; ASM32-NEXT: .vbyte 4, L..func_end0 ; ASM32-NEXT: .byte 0 # End sequence ; ASM32-NEXT: .byte 1 ; ASM32-NEXT: .byte 1 @@ -426,10 +426,10 @@ ; ASM64-NEXT: .byte 3 # Advance line 1 ; ASM64-NEXT: .byte 1 ; ASM64-NEXT: .byte 1 -; ASM64-NEXT: .byte 0 # Set address to L..sec_end0 +; ASM64-NEXT: .byte 0 # Set address to L..func_end0 ; ASM64-NEXT: .byte 9 ; ASM64-NEXT: .byte 2 -; ASM64-NEXT: .vbyte 8, L..sec_end0 +; ASM64-NEXT: .vbyte 8, L..func_end0 ; ASM64-NEXT: .byte 0 # End sequence ; ASM64-NEXT: .byte 1 ; ASM64-NEXT: .byte 1 diff --git a/llvm/test/DebugInfo/XCOFF/explicit-section.ll b/llvm/test/DebugInfo/XCOFF/explicit-section.ll --- a/llvm/test/DebugInfo/XCOFF/explicit-section.ll +++ b/llvm/test/DebugInfo/XCOFF/explicit-section.ll @@ -296,10 +296,10 @@ ; CHECK-NEXT: .byte 3 # Advance line 0 ; CHECK-NEXT: .byte 0 ; CHECK-NEXT: .byte 1 -; CHECK-NEXT: .byte 0 # Set address to L..sec_end0 +; CHECK-NEXT: .byte 0 # Set address to L..func_end0 ; CHECK-NEXT: .byte 5 ; CHECK-NEXT: .byte 2 -; CHECK-NEXT: .vbyte 4, L..sec_end0 +; CHECK-NEXT: .vbyte 4, L..func_end0 ; CHECK-NEXT: .byte 0 # End sequence ; CHECK-NEXT: .byte 1 ; CHECK-NEXT: .byte 1 @@ -328,10 +328,10 @@ ; CHECK-NEXT: .byte 3 # Advance line 0 ; CHECK-NEXT: .byte 0 ; CHECK-NEXT: .byte 1 -; CHECK-NEXT: .byte 0 # Set address to L..sec_end0 +; CHECK-NEXT: .byte 0 # Set address to L..func_end1 ; CHECK-NEXT: .byte 5 ; CHECK-NEXT: .byte 2 -; CHECK-NEXT: .vbyte 4, L..sec_end0 +; CHECK-NEXT: .vbyte 4, L..func_end1 ; CHECK-NEXT: .byte 0 # End sequence ; CHECK-NEXT: .byte 1 ; CHECK-NEXT: .byte 1 diff --git a/llvm/test/DebugInfo/XCOFF/function-sections.ll b/llvm/test/DebugInfo/XCOFF/function-sections.ll --- a/llvm/test/DebugInfo/XCOFF/function-sections.ll +++ b/llvm/test/DebugInfo/XCOFF/function-sections.ll @@ -283,10 +283,10 @@ ; CHECK-NEXT: .byte 3 # Advance line 1 ; CHECK-NEXT: .byte 1 ; CHECK-NEXT: .byte 1 -; CHECK-NEXT: .byte 0 # Set address to L..sec_end0 +; CHECK-NEXT: .byte 0 # Set address to L..func_end0 ; CHECK-NEXT: .byte 5 ; CHECK-NEXT: .byte 2 -; CHECK-NEXT: .vbyte 4, L..sec_end0 +; CHECK-NEXT: .vbyte 4, L..func_end0 ; CHECK-NEXT: .byte 0 # End sequence ; CHECK-NEXT: .byte 1 ; CHECK-NEXT: .byte 1 @@ -305,10 +305,10 @@ ; CHECK-NEXT: .byte 3 # Advance line 1 ; CHECK-NEXT: .byte 1 ; CHECK-NEXT: .byte 1 -; CHECK-NEXT: .byte 0 # Set address to L..sec_end0 +; CHECK-NEXT: .byte 0 # Set address to L..func_end1 ; CHECK-NEXT: .byte 5 ; CHECK-NEXT: .byte 2 -; CHECK-NEXT: .vbyte 4, L..sec_end0 +; CHECK-NEXT: .vbyte 4, L..func_end1 ; CHECK-NEXT: .byte 0 # End sequence ; CHECK-NEXT: .byte 1 ; CHECK-NEXT: .byte 1