[lld] r310046 - [ELF] - Remove ScriptLexer::Error field and check ErrorCount instead.

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 4 03:34:14 PDT 2017


Author: grimar
Date: Fri Aug  4 03:34:14 2017
New Revision: 310046

URL: http://llvm.org/viewvc/llvm-project?rev=310046&view=rev
Log:
[ELF] - Remove ScriptLexer::Error field and check ErrorCount instead.

D35945 introduces change when there is useless to check Error flag
in few places, but ErrorCount must be checked instead.

But then we probably can just check ErrorCount always. That should simplify
things. Patch do that.

Differential revision: https://reviews.llvm.org/D36266

Modified:
    lld/trunk/ELF/ScriptLexer.cpp
    lld/trunk/ELF/ScriptLexer.h
    lld/trunk/ELF/ScriptParser.cpp
    lld/trunk/test/ELF/version-script-err.s

Modified: lld/trunk/ELF/ScriptLexer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptLexer.cpp?rev=310046&r1=310045&r2=310046&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptLexer.cpp (original)
+++ lld/trunk/ELF/ScriptLexer.cpp Fri Aug  4 03:34:14 2017
@@ -75,9 +75,8 @@ ScriptLexer::ScriptLexer(MemoryBufferRef
 
 // We don't want to record cascading errors. Keep only the first one.
 void ScriptLexer::setError(const Twine &Msg) {
-  if (Error)
+  if (ErrorCount)
     return;
-  Error = true;
 
   if (!Pos) {
     error(getCurrentLocation() + ": " + Msg);
@@ -164,7 +163,7 @@ StringRef ScriptLexer::skipSpace(StringR
 }
 
 // An erroneous token is handled as if it were the last token before EOF.
-bool ScriptLexer::atEOF() { return Error || Tokens.size() == Pos; }
+bool ScriptLexer::atEOF() { return ErrorCount || Tokens.size() == Pos; }
 
 // Split a given string as an expression.
 // This function returns "3", "*" and "5" for "3*5" for example.
@@ -207,7 +206,7 @@ static std::vector<StringRef> tokenizeEx
 //
 // This function may split the current token into multiple tokens.
 void ScriptLexer::maybeSplitExpr() {
-  if (!InExpr || Error || atEOF())
+  if (!InExpr || ErrorCount || atEOF())
     return;
 
   std::vector<StringRef> V = tokenizeExpr(Tokens[Pos]);
@@ -220,7 +219,7 @@ void ScriptLexer::maybeSplitExpr() {
 StringRef ScriptLexer::next() {
   maybeSplitExpr();
 
-  if (Error)
+  if (ErrorCount)
     return "";
   if (atEOF()) {
     setError("unexpected EOF");
@@ -231,7 +230,7 @@ StringRef ScriptLexer::next() {
 
 StringRef ScriptLexer::peek() {
   StringRef Tok = next();
-  if (Error)
+  if (ErrorCount)
     return "";
   Pos = Pos - 1;
   return Tok;
@@ -260,7 +259,7 @@ bool ScriptLexer::consumeLabel(StringRef
 void ScriptLexer::skip() { (void)next(); }
 
 void ScriptLexer::expect(StringRef Expect) {
-  if (Error)
+  if (ErrorCount)
     return;
   StringRef Tok = next();
   if (Tok != Expect)

Modified: lld/trunk/ELF/ScriptLexer.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptLexer.h?rev=310046&r1=310045&r2=310046&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptLexer.h (original)
+++ lld/trunk/ELF/ScriptLexer.h Fri Aug  4 03:34:14 2017
@@ -39,7 +39,6 @@ public:
   std::vector<StringRef> Tokens;
   bool InExpr = false;
   size_t Pos = 0;
-  bool Error = false;
 
 private:
   void maybeSplitExpr();

Modified: lld/trunk/ELF/ScriptParser.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/ScriptParser.cpp?rev=310046&r1=310045&r2=310046&view=diff
==============================================================================
--- lld/trunk/ELF/ScriptParser.cpp (original)
+++ lld/trunk/ELF/ScriptParser.cpp Fri Aug  4 03:34:14 2017
@@ -192,7 +192,7 @@ void ScriptParser::readVersionScriptComm
     return;
   }
 
-  while (!atEOF() && !Error && peek() != "}") {
+  while (!atEOF() && !ErrorCount && peek() != "}") {
     StringRef VerStr = next();
     if (VerStr == "{") {
       setError("anonymous version definition is used in "
@@ -284,7 +284,7 @@ void ScriptParser::readAsNeeded() {
   expect("(");
   bool Orig = Config->AsNeeded;
   Config->AsNeeded = true;
-  while (!Error && !consume(")"))
+  while (!ErrorCount && !consume(")"))
     addFile(unquote(next()));
   Config->AsNeeded = Orig;
 }
@@ -300,13 +300,13 @@ void ScriptParser::readEntry() {
 
 void ScriptParser::readExtern() {
   expect("(");
-  while (!Error && !consume(")"))
+  while (!ErrorCount && !consume(")"))
     Config->Undefined.push_back(next());
 }
 
 void ScriptParser::readGroup() {
   expect("(");
-  while (!Error && !consume(")")) {
+  while (!ErrorCount && !consume(")")) {
     if (consume("AS_NEEDED"))
       readAsNeeded();
     else
@@ -345,7 +345,7 @@ void ScriptParser::readOutput() {
 void ScriptParser::readOutputArch() {
   // OUTPUT_ARCH is ignored for now.
   expect("(");
-  while (!Error && !consume(")"))
+  while (!ErrorCount && !consume(")"))
     skip();
 }
 
@@ -364,14 +364,14 @@ void ScriptParser::readOutputFormat() {
 
 void ScriptParser::readPhdrs() {
   expect("{");
-  while (!Error && !consume("}")) {
+  while (!ErrorCount && !consume("}")) {
     Script->Opt.PhdrsCommands.push_back(
         {next(), PT_NULL, false, false, UINT_MAX, nullptr});
 
     PhdrsCommand &PhdrCmd = Script->Opt.PhdrsCommands.back();
     PhdrCmd.Type = readPhdrType();
 
-    while (!Error && !consume(";")) {
+    while (!ErrorCount && !consume(";")) {
       if (consume("FILEHDR"))
         PhdrCmd.HasFilehdr = true;
       else if (consume("PHDRS"))
@@ -403,7 +403,7 @@ void ScriptParser::readSections() {
   Config->SingleRoRx = true;
 
   expect("{");
-  while (!Error && !consume("}")) {
+  while (!ErrorCount && !consume("}")) {
     StringRef Tok = next();
     BaseCommand *Cmd = readProvideOrAssignment(Tok);
     if (!Cmd) {
@@ -428,7 +428,7 @@ static int precedence(StringRef Op) {
 
 StringMatcher ScriptParser::readFilePatterns() {
   std::vector<StringRef> V;
-  while (!Error && !consume(")"))
+  while (!ErrorCount && !consume(")"))
     V.push_back(next());
   return StringMatcher(V);
 }
@@ -460,7 +460,7 @@ SortSectionPolicy ScriptParser::readSort
 // any file but a.o, and section .baz in any file but b.o.
 std::vector<SectionPattern> ScriptParser::readInputSectionsList() {
   std::vector<SectionPattern> Ret;
-  while (!Error && peek() != ")") {
+  while (!ErrorCount && peek() != ")") {
     StringMatcher ExcludeFilePat;
     if (consume("EXCLUDE_FILE")) {
       expect("(");
@@ -468,7 +468,7 @@ std::vector<SectionPattern> ScriptParser
     }
 
     std::vector<StringRef> V;
-    while (!Error && peek() != ")" && peek() != "EXCLUDE_FILE")
+    while (!ErrorCount && peek() != ")" && peek() != "EXCLUDE_FILE")
       V.push_back(next());
 
     if (!V.empty())
@@ -495,7 +495,7 @@ ScriptParser::readInputSectionRules(Stri
   auto *Cmd = make<InputSectionDescription>(FilePattern);
   expect("(");
 
-  while (!Error && !consume(")")) {
+  while (!ErrorCount && !consume(")")) {
     SortSectionPolicy Outer = readSortKind();
     SortSectionPolicy Inner = SortSectionPolicy::Default;
     std::vector<SectionPattern> V;
@@ -625,7 +625,7 @@ OutputSection *ScriptParser::readOutputS
     Cmd->Constraint = ConstraintKind::ReadWrite;
   expect("{");
 
-  while (!Error && !consume("}")) {
+  while (!ErrorCount && !consume("}")) {
     StringRef Tok = next();
     if (Tok == ";") {
       // Empty commands are allowed. Do nothing here.
@@ -769,7 +769,7 @@ static Expr combine(StringRef Op, Expr L
 // This is a part of the operator-precedence parser. This function
 // assumes that the remaining token stream starts with an operator.
 Expr ScriptParser::readExpr1(Expr Lhs, int MinPrec) {
-  while (!atEOF() && !Error) {
+  while (!atEOF() && !ErrorCount) {
     // Read an operator and an expression.
     if (consume("?"))
       return readTernary(Lhs);
@@ -1033,7 +1033,7 @@ Expr ScriptParser::readParenExpr() {
 
 std::vector<StringRef> ScriptParser::readOutputSectionPhdrs() {
   std::vector<StringRef> Phdrs;
-  while (!Error && peek().startswith(":")) {
+  while (!ErrorCount && peek().startswith(":")) {
     StringRef Tok = next();
     Phdrs.push_back((Tok.size() == 1) ? next() : Tok.substr(1));
   }
@@ -1136,7 +1136,7 @@ ScriptParser::readSymbols() {
   std::vector<SymbolVersion> Globals;
   std::vector<SymbolVersion> *V = &Globals;
 
-  while (!Error) {
+  while (!ErrorCount) {
     if (consume("}"))
       break;
     if (consumeLabel("local")) {
@@ -1170,7 +1170,7 @@ std::vector<SymbolVersion> ScriptParser:
   expect("{");
 
   std::vector<SymbolVersion> Ret;
-  while (!Error && peek() != "}") {
+  while (!ErrorCount && peek() != "}") {
     StringRef Tok = next();
     bool HasWildcard = !Tok.startswith("\"") && hasWildcard(Tok);
     Ret.push_back({unquote(Tok), IsCXX, HasWildcard});
@@ -1197,7 +1197,7 @@ uint64_t ScriptParser::readMemoryAssignm
 // MEMORY { name [(attr)] : ORIGIN = origin, LENGTH = len ... }
 void ScriptParser::readMemory() {
   expect("{");
-  while (!Error && !consume("}")) {
+  while (!ErrorCount && !consume("}")) {
     StringRef Name = next();
 
     uint32_t Flags = 0;

Modified: lld/trunk/test/ELF/version-script-err.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/version-script-err.s?rev=310046&r1=310045&r2=310046&view=diff
==============================================================================
--- lld/trunk/test/ELF/version-script-err.s (original)
+++ lld/trunk/test/ELF/version-script-err.s Fri Aug  4 03:34:14 2017
@@ -8,4 +8,3 @@
 // RUN: not ld.lld --version-script %terr1.script -shared %t.o -o %t.so 2>&1 | \
 // RUN:   FileCheck -check-prefix=ERR1 %s
 // ERR1: {{.*}}:1: unclosed quote
-// ERR1-NEXT: {{.*}}: unexpected EOF




More information about the llvm-commits mailing list