diff options
| author | Davide Italiano <davide@freebsd.org> | 2015-09-11 20:47:35 +0000 |
|---|---|---|
| committer | Davide Italiano <davide@freebsd.org> | 2015-09-11 20:47:35 +0000 |
| commit | 63cee81c3c6b083c028ced1114ec50e6a7cae0b3 (patch) | |
| tree | 28f741f0842ec7e67c4e0a92ebc5b580f5d92d01 /llvm/lib/MC | |
| parent | 84bf8a3bc41d82310d35f0f9c789ac673d8d1774 (diff) | |
| download | bcm5719-llvm-63cee81c3c6b083c028ced1114ec50e6a7cae0b3.tar.gz bcm5719-llvm-63cee81c3c6b083c028ced1114ec50e6a7cae0b3.zip | |
[MC] Don't crash on division by zero.
Differential Revision: http://reviews.llvm.org/D12776
llvm-svn: 247471
Diffstat (limited to 'llvm/lib/MC')
| -rw-r--r-- | llvm/lib/MC/MCExpr.cpp | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/lib/MC/MCExpr.cpp b/llvm/lib/MC/MCExpr.cpp index a30ceecc952..90cd7fa07b1 100644 --- a/llvm/lib/MC/MCExpr.cpp +++ b/llvm/lib/MC/MCExpr.cpp @@ -739,7 +739,17 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, case MCBinaryExpr::AShr: Result = LHS >> RHS; break; case MCBinaryExpr::Add: Result = LHS + RHS; break; case MCBinaryExpr::And: Result = LHS & RHS; break; - case MCBinaryExpr::Div: Result = LHS / RHS; break; + case MCBinaryExpr::Div: { + // 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 + // we're bailing out because of 'division by zero'. Therefore, it will + // emit a 'expected relocatable expression' error. It would be nice to + // change this code to emit a better diagnostic. + if (RHS == 0) + return false; + Result = LHS / RHS; break; + } case MCBinaryExpr::EQ: Result = LHS == RHS; break; case MCBinaryExpr::GT: Result = LHS > RHS; break; case MCBinaryExpr::GTE: Result = LHS >= RHS; break; |

