Skip to content

Commit b95cca0

Browse files
committed
[ELF] Improve compound assignment tests
Also use strchr instead of is_contained.
1 parent 97afce0 commit b95cca0

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lld/ELF/ScriptParser.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,8 +1043,7 @@ SymbolAssignment *ScriptParser::readAssignment(StringRef tok) {
10431043
// Support = followed by an expression without whitespace.
10441044
SaveAndRestore<bool> saved(inExpr, true);
10451045
cmd = readSymbolAssignment(tok);
1046-
} else if ((op.size() == 2 && op[1] == '=' &&
1047-
is_contained("*/+-&|", op[0])) ||
1046+
} else if ((op.size() == 2 && op[1] == '=' && strchr("*/+-&|", op[0])) ||
10481047
op == "<<=" || op == ">>=") {
10491048
cmd = readSymbolAssignment(tok);
10501049
} else if (tok == "PROVIDE") {

lld/test/ELF/linkerscript/operators.test

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
SECTIONS {
77
_start = .;
8-
unary =!0 + !0;
8+
unary =!0 + !0; # Test space can be omitted between = and !
99
negate =-1 - 1;
1010
not =~0xffff + 4;
1111
not_negate = -~5 + 1;
@@ -28,9 +28,9 @@ SECTIONS {
2828
ternary2 = 1 ? 2?3:4 : 5?6 :7;
2929

3030
mulassign =2;
31-
mulassign *= 2;
31+
mulassign *=2; # Test space can be omitted after *=
3232
divassign = 8;
33-
divassign /= 2;
33+
divassign /=2;
3434
plusassign =1;
3535
plusassign += 2;
3636
minusassign = 3;
@@ -160,3 +160,11 @@ SECTIONS {
160160
## Div by zero error.
161161
# RUN: echo 'a = 1; a /= 0;' > %t.script
162162
# RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | FileCheck --check-prefix=DIVZERO %s
163+
164+
## GNU ld does not support %= or ^=.
165+
# RUN: echo 'a = 1; a %= 0;' > %t.script
166+
# RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | FileCheck --check-prefix=UNKNOWN %s
167+
# RUN: echo 'a = 1; a ^= 0;' > %t.script
168+
# RUN: not ld.lld %t.o -T %t.script -o /dev/null 2>&1 | FileCheck --check-prefix=UNKNOWN %s
169+
170+
# UNKNOWN: error: {{.*}}:1: unknown directive: a

0 commit comments

Comments
 (0)