[PATCH] D12776: [MC] Don't crash on division by zero
Rafael EspĂndola via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 10 15:00:48 PDT 2015
> +// 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
More information about the llvm-commits
mailing list