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

[ELF] Remove consumeLabel in ScriptLexer #99567

Merged
merged 4 commits into from
Jul 24, 2024

Conversation

hongyu-dev
Copy link
Contributor

This commit removes consumeLabel since we can just use consume function to have the same functionalities.

This commit removes `consumeLabel` since we can just use consume
function to have the same functionalities.
@llvmbot
Copy link
Member

llvmbot commented Jul 18, 2024

@llvm/pr-subscribers-lld

@llvm/pr-subscribers-lld-elf

Author: Hongyu Chen (yugier)

Changes

This commit removes consumeLabel since we can just use consume function to have the same functionalities.


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

3 Files Affected:

  • (modified) lld/ELF/ScriptLexer.cpp (-12)
  • (modified) lld/ELF/ScriptLexer.h (-1)
  • (modified) lld/ELF/ScriptParser.cpp (+2-2)
diff --git a/lld/ELF/ScriptLexer.cpp b/lld/ELF/ScriptLexer.cpp
index 14f39ed10e17c..5ac1c15043ce6 100644
--- a/lld/ELF/ScriptLexer.cpp
+++ b/lld/ELF/ScriptLexer.cpp
@@ -289,18 +289,6 @@ bool ScriptLexer::consume(StringRef tok) {
   return false;
 }
 
-// Consumes Tok followed by ":". Space is allowed between Tok and ":".
-bool ScriptLexer::consumeLabel(StringRef tok) {
-  if (consume((tok + ":").str()))
-    return true;
-  if (tokens.size() >= pos + 2 && tokens[pos] == tok &&
-      tokens[pos + 1] == ":") {
-    pos += 2;
-    return true;
-  }
-  return false;
-}
-
 void ScriptLexer::skip() { (void)next(); }
 
 void ScriptLexer::expect(StringRef expect) {
diff --git a/lld/ELF/ScriptLexer.h b/lld/ELF/ScriptLexer.h
index 7919e493fa28b..b4d2ab8627a91 100644
--- a/lld/ELF/ScriptLexer.h
+++ b/lld/ELF/ScriptLexer.h
@@ -30,7 +30,6 @@ class ScriptLexer {
   void skip();
   bool consume(StringRef tok);
   void expect(StringRef expect);
-  bool consumeLabel(StringRef tok);
   std::string getCurrentLocation();
   MemoryBufferRef getCurrentMB();
 
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index db46263115242..830c4f315a5a8 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -1692,11 +1692,11 @@ ScriptParser::readSymbols() {
   while (!errorCount()) {
     if (consume("}"))
       break;
-    if (consumeLabel("local")) {
+    if (consume("local:") || (consume("local") && consume(":"))) {
       v = &locals;
       continue;
     }
-    if (consumeLabel("global")) {
+    if (consume("global:") || (consume("global") && consume(":"))) {
       v = &globals;
       continue;
     }

v = &locals;
continue;
}
if (consumeLabel("global")) {
if (consume("global:") || (consume("global") && consume(":"))) {
Copy link
Member

Choose a reason for hiding this comment

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

We should check local: and global: below at StringRef tok = next();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I am confused here why we need check local: and global below StringRef tok = next(); ? if the lexer didn't consume global:, global : , local:, local : , or extern, we do not need do other things for the symbol right? Please correct me if I understand here wrong. Thank you!

Copy link
Member

Choose a reason for hiding this comment

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

  • Manually inline the two consumeLabel calls
  • Move the expanded body to below, just above next()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I committed the change but I think it's not what you were trying to say? If it is not could you please specify it more?


if (consume("extern")) {
SmallVector<SymbolVersion, 0> ext = readVersionExtern();
v->insert(v->end(), ext.begin(), ext.end());
} else {
if (consume("local:") || (consume("local") && consume(":"))) {
Copy link
Member

Choose a reason for hiding this comment

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

I think this introduces a bug that a symbol named local or global will not be accepted.

The "local" and "global" name check should be performed after next().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It makes a lot of sense now thank you very much! I just updated it again.

@hongyu-dev hongyu-dev changed the title [lld][ELF] remove consumeLabel in ScriptLexer [ELF] Remove consumeLabel in ScriptLexer Jul 23, 2024
@hongyu-dev hongyu-dev merged commit 2ae862b into llvm:main Jul 24, 2024
7 checks passed
@hongyu-dev hongyu-dev deleted the lld-elf-remove-consumeLabel branch July 24, 2024 05:03
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
Summary:
This commit removes `consumeLabel` since we can just use consume
function to have the same functionalities.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60250691
MaskRay added a commit that referenced this pull request Jul 25, 2024
llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Jul 27, 2024
llvmbot pushed a commit to llvmbot/llvm-project that referenced this pull request Jul 27, 2024
tru pushed a commit to llvmbot/llvm-project that referenced this pull request Jul 29, 2024
Harini0924 pushed a commit to Harini0924/llvm-project that referenced this pull request Aug 1, 2024
This commit removes `consumeLabel` since we can just use consume
function to have the same functionalities.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants