diff --git a/llvm/lib/MC/MCParser/COFFMasmParser.cpp b/llvm/lib/MC/MCParser/COFFMasmParser.cpp index c323e64a40aee..8464a2392680b 100644 --- a/llvm/lib/MC/MCParser/COFFMasmParser.cpp +++ b/llvm/lib/MC/MCParser/COFFMasmParser.cpp @@ -441,6 +441,9 @@ bool COFFMasmParser::parseDirectiveOption(StringRef Directive, SMLoc Loc) { /// statements /// label "endproc" bool COFFMasmParser::parseDirectiveProc(StringRef Directive, SMLoc Loc) { + if (!getStreamer().getCurrentFragment()) + return Error(getTok().getLoc(), "expected section directive"); + StringRef Label; if (getParser().parseIdentifier(Label)) return Error(Loc, "expected identifier for procedure"); diff --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp index 78261c1f9fedb..b2c956e0a4598 100644 --- a/llvm/lib/MC/MCParser/MasmParser.cpp +++ b/llvm/lib/MC/MCParser/MasmParser.cpp @@ -1454,7 +1454,8 @@ bool MasmParser::Run(bool NoInitialTextSection, bool NoFinalize) { } bool MasmParser::checkForValidSection() { - if (!ParsingMSInlineAsm && !getStreamer().getCurrentSectionOnly()) { + if (!ParsingMSInlineAsm && !(getStreamer().getCurrentFragment() && + getStreamer().getCurrentSectionOnly())) { Out.initSections(false, getTargetParser().getSTI()); return Error(getTok().getLoc(), "expected section directive before assembly directive"); diff --git a/llvm/test/tools/llvm-ml/bare_proc_error.asm b/llvm/test/tools/llvm-ml/bare_proc_error.asm new file mode 100644 index 0000000000000..59668edafccf1 --- /dev/null +++ b/llvm/test/tools/llvm-ml/bare_proc_error.asm @@ -0,0 +1,7 @@ +; RUN: not llvm-ml -filetype=s %s /Fo /dev/null 2>&1 | FileCheck %s + +; CHECK: :[[# @LINE+1]]:1: error: expected section directive +foo PROC +; CHECK: :[[# @LINE+1]]:6: error: expected section directive before assembly directive + ret +foo ENDP diff --git a/llvm/test/tools/llvm-ml/no_section_error.asm b/llvm/test/tools/llvm-ml/no_section_error.asm new file mode 100644 index 0000000000000..65c111908b81a --- /dev/null +++ b/llvm/test/tools/llvm-ml/no_section_error.asm @@ -0,0 +1,4 @@ +; RUN: not llvm-ml -filetype=s %s /Fo /dev/null 2>&1 | FileCheck %s + +; CHECK: :[[# @LINE + 1]]:6: error: expected section directive before assembly directive in 'BYTE' directive +BYTE 2, 3, 4