[llvm] r332215 - Correct compatibility with the GNU Assembler's handling of comparison ops
Bill Wendling via llvm-commits
llvm-commits at lists.llvm.org
Sun May 13 22:25:36 PDT 2018
Author: void
Date: Sun May 13 22:25:36 2018
New Revision: 332215
URL: http://llvm.org/viewvc/llvm-project?rev=332215&view=rev
Log:
Correct compatibility with the GNU Assembler's handling of comparison ops
GAS returns -1 for a comparison operator if the result is true and 0 if false.
https://www.sourceware.org/binutils/docs-2.12/as.info/Infix-Ops.html#Infix%20Ops
Modified:
llvm/trunk/lib/MC/MCExpr.cpp
llvm/trunk/test/MC/AsmParser/altmacro_string.s
llvm/trunk/test/MC/AsmParser/directive_space.s
llvm/trunk/test/MC/AsmParser/exprs.s
Modified: llvm/trunk/lib/MC/MCExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCExpr.cpp?rev=332215&r1=332214&r2=332215&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCExpr.cpp (original)
+++ llvm/trunk/lib/MC/MCExpr.cpp Sun May 13 22:25:36 2018
@@ -74,7 +74,10 @@ void MCExpr::print(raw_ostream &OS, cons
case MCUnaryExpr::Not: OS << '~'; break;
case MCUnaryExpr::Plus: OS << '+'; break;
}
+ bool Binary = UE.getSubExpr()->getKind() == MCExpr::Binary;
+ if (Binary) OS << "(";
UE.getSubExpr()->print(OS, MAI);
+ if (Binary) OS << ")";
return;
}
@@ -756,7 +759,8 @@ bool MCExpr::evaluateAsRelocatableImpl(M
// Apple as.
int64_t LHS = LHSValue.getConstant(), RHS = RHSValue.getConstant();
int64_t Result = 0;
- switch (ABE->getOpcode()) {
+ auto Op = ABE->getOpcode();
+ switch (Op) {
case MCBinaryExpr::AShr: Result = LHS >> RHS; break;
case MCBinaryExpr::Add: Result = LHS + RHS; break;
case MCBinaryExpr::And: Result = LHS & RHS; break;
@@ -791,7 +795,21 @@ bool MCExpr::evaluateAsRelocatableImpl(M
case MCBinaryExpr::Xor: Result = LHS ^ RHS; break;
}
- Res = MCValue::get(Result);
+ switch (Op) {
+ default:
+ Res = MCValue::get(Result);
+ break;
+ case MCBinaryExpr::EQ:
+ case MCBinaryExpr::GT:
+ case MCBinaryExpr::GTE:
+ case MCBinaryExpr::LT:
+ case MCBinaryExpr::LTE:
+ case MCBinaryExpr::NE:
+ // A comparison operator returns a -1 if true and 0 if false.
+ Res = MCValue::get(Result ? -1 : 0);
+ break;
+ }
+
return true;
}
}
Modified: llvm/trunk/test/MC/AsmParser/altmacro_string.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/altmacro_string.s?rev=332215&r1=332214&r2=332215&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/altmacro_string.s (original)
+++ llvm/trunk/test/MC/AsmParser/altmacro_string.s Sun May 13 22:25:36 2018
@@ -32,7 +32,7 @@ concat <simple>,<Check>,<0>
# Test #3:
# The altmacro cannot affect the regular less/greater behavior.
-# CHECK: addl $1, %eax
+# CHECK: addl $-1, %eax
# CHECK: addl $0, %eax
.macro fun3 arg1 arg2
Modified: llvm/trunk/test/MC/AsmParser/directive_space.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/directive_space.s?rev=332215&r1=332214&r2=332215&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/directive_space.s (original)
+++ llvm/trunk/test/MC/AsmParser/directive_space.s Sun May 13 22:25:36 2018
@@ -11,11 +11,21 @@ TEST1:
.space 2, 3
# CHECK: TEST2:
+# CHECK: .space 1,3
+TEST2:
+ .space -(2 > 0), 3
+
+# CHECK: TEST3:
# CHECK: .space 1
-TEST2:
+TEST3:
.skip 1
-# CHECK: TEST3
+# CHECK: TEST4
# CHECK: .space TEST0-TEST1
-TEST3:
- .space TEST0 - TEST1
+TEST4:
+ .skip TEST0 - TEST1
+
+# CHECK: TEST5
+# CHECK: .space -((TEST0-TEST1)>0)
+TEST5:
+ .skip -((TEST0 - TEST1) > 0)
Modified: llvm/trunk/test/MC/AsmParser/exprs.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/AsmParser/exprs.s?rev=332215&r1=332214&r2=332215&view=diff
==============================================================================
--- llvm/trunk/test/MC/AsmParser/exprs.s (original)
+++ llvm/trunk/test/MC/AsmParser/exprs.s Sun May 13 22:25:36 2018
@@ -21,12 +21,12 @@ k:
check_expr 1 & 3, 1
check_expr 4 / 2, 2
check_expr 4 / -2, -2
- check_expr 1 == 1, 1
+ check_expr 1 == 1, -1
check_expr 1 == 0, 0
- check_expr 1 > 0, 1
- check_expr 1 >= 1, 1
- check_expr 1 < 2, 1
- check_expr 1 <= 1, 1
+ check_expr 1 > 0, -1
+ check_expr 1 >= 1, -1
+ check_expr 1 < 2, -1
+ check_expr 1 <= 1, -1
check_expr 4 % 3, 1
check_expr 2 * 2, 4
check_expr 2 != 2, 0
@@ -43,7 +43,7 @@ k:
check_expr 1 || 2, 1
check_expr 0 || 1, 1
check_expr 0 || 0, 0
- check_expr 1 + 2 < 3 + 4, 1
+ check_expr 1 + 2 < 3 + 4, -1
check_expr 1 << 8 - 1, 128
check_expr 3 * 9 - 2 * 9 + 1, 10
More information about the llvm-commits
mailing list