[llvm] r325810 - [MC] Don't crash on modulo by zero (PR35650)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 22 10:06:48 PST 2018
Author: rksimon
Date: Thu Feb 22 10:06:48 2018
New Revision: 325810
URL: http://llvm.org/viewvc/llvm-project?rev=325810&view=rev
Log:
[MC] Don't crash on modulo by zero (PR35650)
Extension to D12776, handle modulo by zero in the same way we handle divide by zero.
Differential Revision: https://reviews.llvm.org/D43631
Modified:
llvm/trunk/lib/MC/MCExpr.cpp
llvm/trunk/test/MC/ELF/div-by-zero.s
Modified: llvm/trunk/lib/MC/MCExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCExpr.cpp?rev=325810&r1=325809&r2=325810&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCExpr.cpp (original)
+++ llvm/trunk/lib/MC/MCExpr.cpp Thu Feb 22 10:06:48 2018
@@ -754,6 +754,7 @@ bool MCExpr::evaluateAsRelocatableImpl(M
case MCBinaryExpr::Add: Result = LHS + RHS; break;
case MCBinaryExpr::And: Result = LHS & RHS; break;
case MCBinaryExpr::Div:
+ case MCBinaryExpr::Mod:
// Handle division by zero. gas just emits a warning and keeps going,
// we try to be stricter.
// FIXME: Currently the caller of this function has no way to understand
@@ -762,7 +763,10 @@ bool MCExpr::evaluateAsRelocatableImpl(M
// change this code to emit a better diagnostic.
if (RHS == 0)
return false;
- Result = LHS / RHS;
+ if (ABE->getOpcode() == MCBinaryExpr::Div)
+ Result = LHS / RHS;
+ else
+ Result = LHS % RHS;
break;
case MCBinaryExpr::EQ: Result = LHS == RHS; break;
case MCBinaryExpr::GT: Result = LHS > RHS; break;
@@ -772,7 +776,6 @@ bool MCExpr::evaluateAsRelocatableImpl(M
case MCBinaryExpr::LShr: Result = uint64_t(LHS) >> uint64_t(RHS); break;
case MCBinaryExpr::LT: Result = LHS < RHS; break;
case MCBinaryExpr::LTE: Result = LHS <= RHS; break;
- case MCBinaryExpr::Mod: Result = LHS % RHS; break;
case MCBinaryExpr::Mul: Result = LHS * RHS; break;
case MCBinaryExpr::NE: Result = LHS != RHS; break;
case MCBinaryExpr::Or: Result = LHS | RHS; break;
Modified: llvm/trunk/test/MC/ELF/div-by-zero.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/ELF/div-by-zero.s?rev=325810&r1=325809&r2=325810&view=diff
==============================================================================
--- llvm/trunk/test/MC/ELF/div-by-zero.s (original)
+++ llvm/trunk/test/MC/ELF/div-by-zero.s Thu Feb 22 10:06:48 2018
@@ -4,3 +4,6 @@
// CHECK: expected relocatable expression
.int 1/0
+
+// CHECK: expected relocatable expression
+.int 2%0
More information about the llvm-commits
mailing list