forked from OSchip/llvm-project
[ELF] Fix precedence of == and != in expressions
In GNU ld, the == and != operators have lower precedence than < > <= >=. This behavior matches C.
This commit is contained in:
parent
3d37e785c7
commit
d479b2e4db
|
@ -636,14 +636,15 @@ void ScriptParser::readTarget() {
|
|||
|
||||
static int precedence(StringRef op) {
|
||||
return StringSwitch<int>(op)
|
||||
.Cases("*", "/", "%", 8)
|
||||
.Cases("+", "-", 7)
|
||||
.Cases("<<", ">>", 6)
|
||||
.Cases("<", "<=", ">", ">=", "==", "!=", 5)
|
||||
.Case("&", 4)
|
||||
.Case("|", 3)
|
||||
.Case("&&", 2)
|
||||
.Case("||", 1)
|
||||
.Cases("*", "/", "%", 10)
|
||||
.Cases("+", "-", 9)
|
||||
.Cases("<<", ">>", 8)
|
||||
.Cases("<", "<=", ">", ">=", 7)
|
||||
.Cases("==", "!=", 6)
|
||||
.Case("&", 5)
|
||||
.Case("|", 4)
|
||||
.Case("&&", 3)
|
||||
.Case("||", 2)
|
||||
.Default(-1);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ SECTIONS {
|
|||
greater = 0 > 1 ? 1 : 2;
|
||||
greatereq = 1 >= 1 ? 1 : 2;
|
||||
eq = 1 == 1 ? 1 : 2;
|
||||
neq = 1 != 1 ? 1 : 2;
|
||||
neq = (1 != 1 <= 1) ? 1 : 2;
|
||||
plusassign = 1;
|
||||
plusassign += 2;
|
||||
unary = -1 + 3;
|
||||
|
|
Loading…
Reference in New Issue