Maybe there's a better way to handle this case (in the Parser?), but at least we now don't crash with FPE on such cases. Also, FWIW, gas seems to handle this in the same exact way (+ emitting a warning)
Details
Details
Diff Detail
Diff Detail
- Repository
- rL LLVM
Event Timeline
Comment Actions
+ Check that llvm-mc doesn't crash on division by zero.
+ RUN: llvm-mc -triple x86_64-pc-linux-gnu %s -o - 2>&1
+
+.int 1/0
Does it work with -filetype=obj? What is output?
Index: lib/MC/MCExpr.cpp
- lib/MC/MCExpr.cpp
+++ lib/MC/MCExpr.cpp
@@ -734,6 +734,11 @@// width, and gas defines the result of comparisons differently from // Apple as. int64_t LHS = LHSValue.getConstant(), RHS = RHSValue.getConstant();+
+ // Handle division by zero.
+ if (ABE->getOpcode() == MCBinaryExpr::Div && RHS == 0)
+ return false;
+
Move the check to the "case MCBinaryExpr::Div:" bellow.
int64_t Result = 0; switch (ABE->getOpcode()) { case MCBinaryExpr::AShr: Result = LHS >> RHS; break;
Cheers,
Rafael