diff options
| author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2018-02-22 18:06:48 +0000 |
|---|---|---|
| committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2018-02-22 18:06:48 +0000 |
| commit | 8831f6e57d3ae3900ffea269aabe468ba48e87c8 (patch) | |
| tree | 4e2c276d227f9f7c2a78f750e0099d8a0c54c7ae /llvm/lib/MC | |
| parent | 925529b821142cdbb448d7432bd2a1724b068c02 (diff) | |
| download | bcm5719-llvm-8831f6e57d3ae3900ffea269aabe468ba48e87c8.tar.gz bcm5719-llvm-8831f6e57d3ae3900ffea269aabe468ba48e87c8.zip | |
[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
llvm-svn: 325810
Diffstat (limited to 'llvm/lib/MC')
| -rw-r--r-- | llvm/lib/MC/MCExpr.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp index f8fff4414f4..c4592aa1567 100644 --- a/llvm/lib/MC/MCExpr.cpp +++ b/llvm/lib/MC/MCExpr.cpp @@ -754,6 +754,7 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, 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(MCValue &Res, const MCAssembler *Asm, // 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(MCValue &Res, const MCAssembler *Asm, 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; |

