Skip to content

Conversation

@ericastor
Copy link
Contributor

@ericastor ericastor commented Jan 17, 2025

This call was made unsafe recently, but was not fixed in db48f1a (the commit that fixed the parallel code in AsmParser.cpp).

Fixes #123189

@ericastor ericastor requested a review from MaskRay January 17, 2025 15:29
@llvmbot llvmbot added the llvm:mc Machine (object) code label Jan 17, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 17, 2025

@llvm/pr-subscribers-mc

Author: Eric Astor (ericastor)

Changes

This call was made unsafe recently, but was not fixed in db48f1a (the commit that fixed the parallel code in AsmParser.cpp).


Full diff: https://github.com/llvm/llvm-project/pull/123355.diff

1 Files Affected:

  • (modified) llvm/lib/MC/MCParser/MasmParser.cpp (+1-1)
diff --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp
index 78261c1f9fedb2..6c49a17180f27b 100644
--- a/llvm/lib/MC/MCParser/MasmParser.cpp
+++ b/llvm/lib/MC/MCParser/MasmParser.cpp
@@ -1454,7 +1454,7 @@ bool MasmParser::Run(bool NoInitialTextSection, bool NoFinalize) {
 }
 
 bool MasmParser::checkForValidSection() {
-  if (!ParsingMSInlineAsm && !getStreamer().getCurrentSectionOnly()) {
+  if (!ParsingMSInlineAsm && !getStreamer().getCurrentFragment()) {
     Out.initSections(false, getTargetParser().getSTI());
     return Error(getTok().getLoc(),
                  "expected section directive before assembly directive");

@MaskRay
Copy link
Member

MaskRay commented Jan 17, 2025

Could you add a test?

@ericastor
Copy link
Contributor Author

I can try to minimize the issue & convert it into a test, but I'm not quite clear on what circumstances actually provoke it. For example, neither db48f1a nor 626eef5 seemed to include a test to verify that their changes were separately safe?

@ericastor
Copy link
Contributor Author

Added tests as requested.

@MaskRay
Copy link
Member

MaskRay commented Jan 17, 2025

The two commits intended to simplify MC internals.
For the gas compatible AsmParser.cpp, we have comprehensive tests and passing the testsuite gives contributors very high confidence in the patches.
I apologize if the simplification actually caused regression to MasmParser.cpp. That was not my intention.

That said, I should be honest. I am deeply concerned with the state of MasmParser.cpp.
When MasmParser.cpp was forked from AsmParser.cpp, it copied a lot of code from AsmParser.
A lot of pieces are unreachable or untested for llvm-ml.

I don't think it is reasonable to require contributors that refactor MC to understand
llvm-ml internals and make perfect judgement on whether a refactoring will regress llvm-ml or not.
You have to write tests to guard against regressions.

/// label "endproc"
bool COFFMasmParser::parseDirectiveProc(StringRef Directive, SMLoc Loc) {
if (!getStreamer().getCurrentFragment()) {
return Error(getTok().getLoc(), "expected section directive before '" +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The convention is to just state expected something and omit before directive .... The before directive information is obvious from the source line that is printed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revised accordingly.

@ericastor
Copy link
Contributor Author

ericastor commented Jan 17, 2025

The two commits intended to simplify MC internals. For the gas compatible AsmParser.cpp, we have comprehensive tests and passing the testsuite gives contributors very high confidence in the patches. I apologize if the simplification actually caused regression to MasmParser.cpp. That was not my intention.

That said, I should be honest. I am deeply concerned with the state of MasmParser.cpp. When MasmParser.cpp was forked from AsmParser.cpp, it copied a lot of code from AsmParser. A lot of pieces are unreachable or untested for llvm-ml.

I don't think it is reasonable to require contributors that refactor MC to understand llvm-ml internals and make perfect judgement on whether a refactoring will regress llvm-ml or not. You have to write tests to guard against regressions.

I agree. To be honest, I was surprised the test suite didn't already cover this case, so this was definitely a mistake on my part. I'm just interested which tests (EDIT: for the base AsmParser) detected the issue with this refactor of MC, but I'm pleased to hear that they were broken and detected the issue before submission.

In terms of reducing MasmParser.cpp... I agree that it could use a lot of cleanup. I would very much like to work on improving the test case coverage. Is there an easy way to get coverage reporting out of the LLVM test suite? I'm apparently not familiar with it, and since it's very much designed as more of an integration-test framework, I don't know any obvious tricks.

/// label "endproc"
bool COFFMasmParser::parseDirectiveProc(StringRef Directive, SMLoc Loc) {
if (!getStreamer().getCurrentFragment()) {
return Error(getTok().getLoc(), "expected section directive");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

omit braces for the single line simple statement

@@ -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 before 'PROC' directive
Copy link
Member

@MaskRay MaskRay Jan 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok, but in the majority of tests we omit spaces beside +: LINE+1

@ericastor ericastor merged commit a94226f into llvm:main Jan 24, 2025
8 checks passed
@ericastor ericastor deleted the llvm-ml branch January 24, 2025 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:mc Machine (object) code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ms] [llvm-ml] SIGSEGV in checkForValidSection in MasmParser

3 participants