break;
}
case BO_Div: {
+ if (RHSFX.getValue() == 0) {
+ Info.FFDiag(E, diag::note_expr_divide_by_zero);
+ return false;
+ }
Result = LHSFX.div(RHSFX, &OpOverflow)
.convert(ResultFXSema, &ConversionOverflow);
break;
llvm::APInt::sdivrem(ThisVal, OtherVal, Result, Rem);
// If the quotient is negative and the remainder is nonzero, round
// towards negative infinity by subtracting epsilon from the result.
- if (Result.isNegative() && !Rem.isNullValue())
+ if (ThisVal.isNegative() != OtherVal.isNegative() && !Rem.isNullValue())
Result = Result - 1;
} else
Result = ThisVal.udiv(OtherVal);
// CHECK-DAG: @sa_const13 = {{.*}}global i16 1, align 2
short _Accum sa_const14 = -0.0234375hk / 2.0hk;
// CHECK-DAG: @sa_const14 = {{.*}}global i16 -2, align 2
+short _Accum sa_const15 = -0.0078125hk / 255.28125hk;
+// CHECK-DAG: @sa_const15 = {{.*}}global i16 -1, align 2
void SignedDivision() {
// CHECK-LABEL: SignedDivision
short _Accum sub_sat = (_Sat short _Accum)-200.0hk - 80.0hk;
short _Accum mul_sat = (_Sat short _Accum)80.0hk * 10.0hk;
short _Fract div_sat = (_Sat short _Fract)0.9hr / 0.1hr;
+
+// Division by zero
+short _Accum div_zero = 4.5k / 0.0lr; // expected-error {{initializer element is not a compile-time constant}}