[lld] b95cca0 - [ELF] Improve compound assignment tests

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 25 22:30:56 PDT 2022


Author: Fangrui Song
Date: 2022-06-25T22:30:52-07:00
New Revision: b95cca03cd7b751e977fee808b7e84ffffec116d

URL: https://github.com/llvm/llvm-project/commit/b95cca03cd7b751e977fee808b7e84ffffec116d
DIFF: https://github.com/llvm/llvm-project/commit/b95cca03cd7b751e977fee808b7e84ffffec116d.diff

LOG: [ELF] Improve compound assignment tests

Also use strchr instead of is_contained.

Added: 
    

Modified: 
    lld/ELF/ScriptParser.cpp
    lld/test/ELF/linkerscript/operators.test

Removed: 
    


################################################################################
diff  --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index b3cc47990552..4d73541b3d42 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -1043,8 +1043,7 @@ SymbolAssignment *ScriptParser::readAssignment(StringRef tok) {
     // Support = followed by an expression without whitespace.
     SaveAndRestore<bool> saved(inExpr, true);
     cmd = readSymbolAssignment(tok);
-  } else if ((op.size() == 2 && op[1] == '=' &&
-              is_contained("*/+-&|", op[0])) ||
+  } else if ((op.size() == 2 && op[1] == '=' && strchr("*/+-&|", op[0])) ||
              op == "<<=" || op == ">>=") {
     cmd = readSymbolAssignment(tok);
   } else if (tok == "PROVIDE") {

diff  --git a/lld/test/ELF/linkerscript/operators.test b/lld/test/ELF/linkerscript/operators.test
index 9ca13c66970a..5fb73c62c63e 100644
--- a/lld/test/ELF/linkerscript/operators.test
+++ b/lld/test/ELF/linkerscript/operators.test
@@ -5,7 +5,7 @@
 
 SECTIONS {
   _start = .;
-  unary =!0 + !0;
+  unary =!0 + !0;  # Test space can be omitted between = and !
   negate =-1 - 1;
   not =~0xffff + 4;
   not_negate = -~5 + 1;
@@ -28,9 +28,9 @@ SECTIONS {
   ternary2 = 1 ? 2?3:4 : 5?6 :7;
 
   mulassign =2;
-  mulassign *= 2;
+  mulassign *=2;  # Test space can be omitted after *=
   divassign = 8;
-  divassign /= 2;
+  divassign /=2;
   plusassign =1;
   plusassign += 2;
   minusassign = 3;
@@ -160,3 +160,11 @@ SECTIONS {
 ## Div by zero error.
 # RUN: echo 'a = 1; a /= 0;' > %t.script
 # RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | FileCheck --check-prefix=DIVZERO %s
+
+## GNU ld does not support %= or ^=.
+# RUN: echo 'a = 1; a %= 0;' > %t.script
+# RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | FileCheck --check-prefix=UNKNOWN %s
+# RUN: echo 'a = 1; a ^= 0;' > %t.script
+# RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | FileCheck --check-prefix=UNKNOWN %s
+
+# UNKNOWN: error: {{.*}}:1: unknown directive: a


        


More information about the llvm-commits mailing list