diff --git a/llvm/include/llvm/MC/MCStreamer.h b/llvm/include/llvm/MC/MCStreamer.h --- a/llvm/include/llvm/MC/MCStreamer.h +++ b/llvm/include/llvm/MC/MCStreamer.h @@ -1064,7 +1064,7 @@ /// Streamer specific finalization. virtual void finishImpl(); /// Finish emission of machine code. - void Finish(); + void Finish(SMLoc EndLoc = SMLoc()); virtual bool mayHaveInstructions(MCSection &Sec) const { return true; } }; diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -994,7 +994,7 @@ // Finalize the output stream if there are no errors and if the client wants // us to. if (!HadError && !NoFinalize) - Out.Finish(); + Out.Finish(Lexer.getLoc()); return HadError || getContext().hadError(); } diff --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp --- a/llvm/lib/MC/MCParser/MasmParser.cpp +++ b/llvm/lib/MC/MCParser/MasmParser.cpp @@ -1280,7 +1280,7 @@ // Finalize the output stream if there are no errors and if the client wants // us to. if (!HadError && !NoFinalize) - Out.Finish(); + Out.Finish(Lexer.getLoc()); return HadError || getContext().hadError(); } diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -273,9 +273,9 @@ MCDwarfFrameInfo *MCStreamer::getCurrentDwarfFrameInfo() { if (!hasUnfinishedDwarfFrameInfo()) { - getContext().reportError(SMLoc(), "this directive must appear between " - ".cfi_startproc and .cfi_endproc " - "directives"); + getContext().reportError(getStartTokLoc(), + "this directive must appear between " + ".cfi_startproc and .cfi_endproc directives"); return nullptr; } return &DwarfFrameInfos.back(); @@ -967,10 +967,10 @@ void MCStreamer::EmitWindowsUnwindTables() { } -void MCStreamer::Finish() { +void MCStreamer::Finish(SMLoc EndLoc) { if ((!DwarfFrameInfos.empty() && !DwarfFrameInfos.back().End) || (!WinFrameInfos.empty() && !WinFrameInfos.back()->End)) { - getContext().reportError(SMLoc(), "Unfinished frame!"); + getContext().reportError(EndLoc, "Unfinished frame!"); return; } diff --git a/llvm/test/MC/X86/cfi-open-within-another-crash.s b/llvm/test/MC/X86/cfi-open-within-another-crash.s --- a/llvm/test/MC/X86/cfi-open-within-another-crash.s +++ b/llvm/test/MC/X86/cfi-open-within-another-crash.s @@ -12,7 +12,7 @@ .globl proc_two proc_two: .cfi_startproc - +# CHECK: [[#@LINE]]:1: error: starting new .cfi frame before finishing the previous one + .cfi_endproc -# CHECK: error: starting new .cfi frame before finishing the previous one diff --git a/llvm/test/MC/X86/cfi-scope-errors.s b/llvm/test/MC/X86/cfi-scope-errors.s --- a/llvm/test/MC/X86/cfi-scope-errors.s +++ b/llvm/test/MC/X86/cfi-scope-errors.s @@ -3,23 +3,23 @@ .text .cfi_def_cfa rsp, 8 -# CHECK: error: this directive must appear between .cfi_startproc and .cfi_endproc directives +# CHECK: [[#@LINE-1]]:1: error: this directive must appear between .cfi_startproc and .cfi_endproc directives .cfi_startproc nop -# TODO(kristina): As Reid suggested, this now supports source locations as a side effect -# of another patch aimed at fixing the crash that would occur here, however the other -# ones do not unfortunately. Will address it in a further patch propogating SMLoc down to -# other CFI directives at which point more LINE checks can be added to ensure proper source -# location reporting. - -# This tests source location correctness as well as the error and it not crashing. -# CHECK: [[@LINE+2]]:1: error: starting new .cfi frame before finishing the previous one +## This tests source location correctness as well as the error and it not crashing. +# CHECK: [[#@LINE+2]]:1: error: starting new .cfi frame before finishing the previous one .cfi_startproc nop .cfi_endproc .cfi_def_cfa rsp, 8 -# CHECK: error: this directive must appear between .cfi_startproc and .cfi_endproc directives +# CHECK: [[#@LINE-1]]:1: error: this directive must appear between .cfi_startproc and .cfi_endproc directives + +## Check we don't crash on unclosed frame scope. +.globl foo +foo: + .cfi_startproc +# CHECK: [[#@LINE+1]]:1: error: Unfinished frame! diff --git a/llvm/test/MC/X86/cfi-scope-unclosed.s b/llvm/test/MC/X86/cfi-scope-unclosed.s deleted file mode 100644 --- a/llvm/test/MC/X86/cfi-scope-unclosed.s +++ /dev/null @@ -1,10 +0,0 @@ -# RUN: not llvm-mc %s -filetype=obj -triple=x86_64-unknown-linux \ -# RUN: -o /dev/null 2>&1 | FileCheck %s - -## Check we don't crash on unclosed frame scope. -# CHECK: error: Unfinished frame! - -.text -.globl foo -foo: - .cfi_startproc