Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[X86AsmParser] IntelExpression: End of Statement should check for valid end state #95677

Merged

Conversation

v01dXYZ
Copy link
Contributor

@v01dXYZ v01dXYZ commented Jun 15, 2024

The following commit bfb7099 added a special case for End of Statement that doesn't check if the state machine is rightfully in a state where ending is valid.

This PR suggest to revert this change to make EndOfStatement processed as any other tokens that are not consumable by the state machine.

Fixes #94446

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be
notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write
permissions for the repository. In which case you can instead tag reviewers by
name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review
by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate
is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

@v01dXYZ v01dXYZ force-pushed the 94446-x86-asm-parser-expr-end-of-statement branch from b64b17c to b5bf7c3 Compare June 18, 2024 16:31
@v01dXYZ v01dXYZ marked this pull request as ready for review June 18, 2024 16:32
@llvmbot
Copy link
Collaborator

llvmbot commented Jun 18, 2024

@llvm/pr-subscribers-mc

@llvm/pr-subscribers-backend-x86

Author: None (v01dXYZ)

Changes

The following commit bfb7099 added a special case for End of Statement that doesn't check if the state machine is rightfully in a state where ending is valid.

This PR suggest to revert this change to make EndOfStatement processed as any other tokens that are not consumable by the state machine.

Fixes #94446


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

1 Files Affected:

  • (modified) llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp (+2-4)
diff --git a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
index 6623106109316..d338607acbabe 100644
--- a/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
+++ b/llvm/lib/Target/X86/AsmParser/X86AsmParser.cpp
@@ -473,7 +473,8 @@ class X86AsmParser : public MCTargetAsmParser {
     unsigned getLength() const { return CurType.Length; }
     int64_t getImm() { return Imm + IC.execute(); }
     bool isValidEndState() const {
-      return State == IES_RBRAC || State == IES_INTEGER;
+      return State == IES_RBRAC || State == IES_RPAREN ||
+             State == IES_INTEGER || State == IES_REGISTER;
     }
 
     // Is the intel expression appended after an operand index.
@@ -1897,9 +1898,6 @@ bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) {
     case AsmToken::Error:
       return Error(getLexer().getErrLoc(), getLexer().getErr());
       break;
-    case AsmToken::EndOfStatement:
-      Done = true;
-      break;
     case AsmToken::Real:
       // DotOperator: [ebx].0
       UpdateLocLex = false;

@v01dXYZ v01dXYZ force-pushed the 94446-x86-asm-parser-expr-end-of-statement branch from b5bf7c3 to d6e252c Compare June 23, 2024 17:46
@v01dXYZ
Copy link
Contributor Author

v01dXYZ commented Jun 23, 2024

FYI, linux CI fails because of a (flaky ?) lldb test with a timeout.

@v01dXYZ v01dXYZ force-pushed the 94446-x86-asm-parser-expr-end-of-statement branch from d6e252c to c00cb20 Compare June 24, 2024 09:15
@v01dXYZ
Copy link
Contributor Author

v01dXYZ commented Jun 24, 2024

I repush the same commit to relaunch the CI. If you know a way to relaunch a failed CI pipeline, I want to know it too.

@v01dXYZ
Copy link
Contributor Author

v01dXYZ commented Jul 1, 2024

Ping

@KanRobert
Copy link
Contributor

AsmParser is shared by assembler and fronr-end. Could you add a .s test to show what you fixed?

@llvmbot llvmbot added the mc Machine (object) code label Jul 5, 2024
@v01dXYZ
Copy link
Contributor Author

v01dXYZ commented Jul 10, 2024

Ping.

I added the case from the issue.

Copy link
Contributor

@KanRobert KanRobert left a comment

Choose a reason for hiding this comment

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

Maybe we can refactor X86AsmParser::ParseIntelExpression to avoid so much customized code. But it looks good as a quick fix.

@v01dXYZ
Copy link
Contributor Author

v01dXYZ commented Jul 15, 2024

I wonder if a customised AsmParser could potentially do it. Is it possible and worth it according to you ? There is certainly a reason why this machinery was not used at the time.

@KanRobert
Copy link
Contributor

I wonder if a customised AsmParser could potentially do it. Is it possible and worth it according to you ? There is certainly a reason why this machinery was not used at the time.

TBH, I am not clear about the history. This is a good wish of myself.

@v01dXYZ
Copy link
Contributor Author

v01dXYZ commented Jul 15, 2024

FYI I don't have merge rights. if you consider the patch good enough, could you merge it on my behalf ?

I'll take a look at trying to replace some parts of the custom Expression Parser by the generic AsmParser at the beginning of next month as it is an interesting task about a very specific part of LLVM (thus perfect for a beginner like me). The code I'll write won't matter as much as the documentation about the suggestions.

@KanRobert
Copy link
Contributor

FYI I don't have merge rights. if you consider the patch good enough, could you merge it on my behalf ?

Sure.

@KanRobert KanRobert merged commit 25752a4 into llvm:main Jul 16, 2024
7 checks passed
Copy link

@v01dXYZ Congratulations on having your first Pull Request (PR) merged into the LLVM Project!

Your changes will be combined with recent changes from other authors, then tested
by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR.

Please check whether problems have been caused by your change specifically, as
the builds can include changes from many authors. It is not uncommon for your
change to be included in a build that fails due to someone else's changes, or
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail here.

If your change does cause a problem, it may be reverted, or you can revert it yourself.
This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are working as expected, well done!

@llvm-ci
Copy link
Collaborator

llvm-ci commented Jul 16, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-4 while building llvm at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/1904

Here is the relevant piece of the build log for the reference:

Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'LLVM :: Analysis/StructuralHash/structural-hash-printer.ll' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/opt -passes='print<structural-hash>' -disable-output /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll 2>&1 | /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/opt '-passes=print<structural-hash>' -disable-output /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll
RUN: at line 2: /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/opt -passes='print<structural-hash><detailed>' -disable-output /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll 2>&1 | /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll -check-prefix=DETAILED-HASH
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/opt '-passes=print<structural-hash><detailed>' -disable-output /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll -check-prefix=DETAILED-HASH
�[1m/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll:21:18: �[0m�[0;1;31merror: �[0m�[1mDETAILED-HASH: expected string not found in input
�[0m; DETAILED-HASH: Module Hash: {{([a-z0-9]{14,})}}
�[0;1;32m                 ^
�[0m�[1m<stdin>:1:1: �[0m�[0;1;30mnote: �[0m�[1mscanning from here
�[0mModule Hash: 8d6dc22990ebe
�[0;1;32m^
�[0m
Input file: <stdin>
Check file: /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/llvm/test/Analysis/StructuralHash/structural-hash-printer.ll

-dump-input=help explains the following input dump.

Input was:
<<<<<<
�[1m�[0m�[0;1;30m          1: �[0m�[1m�[0;1;46mModule Hash: 8d6dc22990ebe �[0m
�[0;1;31mcheck:21     X~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
�[0m�[0;1;30m          2: �[0m�[1m�[0;1;46mFunction f1 Hash: 7062c67049c6f99c �[0m
�[0;1;31mcheck:21     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m          3: �[0m�[1m�[0;1;46mFunction f2 Hash: 1e47c72d08a2afcd �[0m
�[0;1;31mcheck:21     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m>>>>>>

--

********************


yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
…id end state (#95677)

Summary:
The following commit bfb7099 added a
special case for End of Statement that doesn't check if the state
machine is rightfully in a state where ending is valid.

This PR suggest to revert this change to make `EndOfStatement` processed
as any other tokens that are not consumable by the state machine.

Fixes #94446

---------

Co-authored-by: v01dxyz <[email protected]>

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60251503
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 mc Machine (object) code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"SmallVector unable to grow" reached via parseIntelOperand with rejectable asm
4 participants