if (mpz_sizeinbase(val, 2) > 0x100000)
{
error_at(location, "constant addition overflow");
+ nc->set_invalid();
mpz_set_ui(val, 1);
}
break;
if (mpz_sizeinbase(val, 2) > 0x100000)
{
error_at(location, "constant subtraction overflow");
+ nc->set_invalid();
mpz_set_ui(val, 1);
}
break;
if (mpz_sizeinbase(val, 2) > 0x100000)
{
error_at(location, "constant multiplication overflow");
+ nc->set_invalid();
mpz_set_ui(val, 1);
}
break;
else
{
error_at(location, "division by zero");
+ nc->set_invalid();
mpz_set_ui(val, 0);
}
break;
else
{
error_at(location, "division by zero");
+ nc->set_invalid();
mpz_set_ui(val, 0);
}
break;
else
{
error_at(location, "shift count overflow");
+ nc->set_invalid();
mpz_set_ui(val, 1);
}
break;
if (mpz_cmp_ui(right_val, shift) != 0)
{
error_at(location, "shift count overflow");
+ nc->set_invalid();
mpz_set_ui(val, 1);
}
else
else
{
error_at(location, "division by zero");
+ nc->set_invalid();
mpfr_set_ui(val, 0, GMP_RNDN);
}
break;
if (mpc_cmp_si(right_val, 0) == 0)
{
error_at(location, "division by zero");
+ nc->set_invalid();
mpc_set_ui(val, 0, MPC_RNDNN);
break;
}
Numeric_constant nc;
if (!Binary_expression::eval_constant(op, &left_nc, &right_nc,
location, &nc))
- return this;
+ {
+ if (nc.is_invalid())
+ {
+ go_assert(saw_errors());
+ return Expression::make_error(location);
+ }
+ return this;
+ }
return nc.expression(location);
}
}
bool
Numeric_constant::check_int_type(Integer_type* type, bool issue_error,
- Location location) const
+ Location location)
{
mpz_t val;
switch (this->classification_)
if (!mpfr_integer_p(this->u_.float_val))
{
if (issue_error)
- error_at(location, "floating point constant truncated to integer");
+ {
+ error_at(location,
+ "floating point constant truncated to integer");
+ this->set_invalid();
+ }
return false;
}
mpz_init(val);
|| !mpfr_zero_p(mpc_imagref(this->u_.complex_val)))
{
if (issue_error)
- error_at(location, "complex constant truncated to integer");
+ {
+ error_at(location, "complex constant truncated to integer");
+ this->set_invalid();
+ }
return false;
}
mpz_init(val);
}
if (!ret && issue_error)
- error_at(location, "integer constant overflow");
+ {
+ error_at(location, "integer constant overflow");
+ this->set_invalid();
+ }
return ret;
}
if (!mpfr_zero_p(mpc_imagref(this->u_.complex_val)))
{
if (issue_error)
- error_at(location, "complex constant truncated to float");
+ {
+ this->set_invalid();
+ error_at(location, "complex constant truncated to float");
+ }
return false;
}
mpfr_init_set(val, mpc_realref(this->u_.complex_val), GMP_RNDN);
mpfr_clear(val);
if (!ret && issue_error)
- error_at(location, "floating point constant overflow");
+ {
+ error_at(location, "floating point constant overflow");
+ this->set_invalid();
+ }
return ret;
}
&& mpfr_get_exp(mpc_realref(val)) > max_exp)
{
if (issue_error)
- error_at(location, "complex real part overflow");
+ {
+ error_at(location, "complex real part overflow");
+ this->set_invalid();
+ }
ret = false;
}
&& mpfr_get_exp(mpc_imagref(val)) > max_exp)
{
if (issue_error)
- error_at(location, "complex imaginary part overflow");
+ {
+ error_at(location, "complex imaginary part overflow");
+ this->set_invalid();
+ }
ret = false;
}
return Expression::make_float(&this->u_.float_val, this->type_, loc);
case NC_COMPLEX:
return Expression::make_complex(&this->u_.complex_val, this->type_, loc);
+ case NC_INVALID:
+ go_assert(saw_errors());
+ return Expression::make_error(loc);
default:
go_unreachable();
}
void
set_complex(Type*, const mpc_t);
+ // Mark numeric constant as invalid.
+ void
+ set_invalid()
+ { this->classification_ = NC_INVALID; }
+
// Classifiers.
bool
is_int() const
is_complex() const
{ return this->classification_ == Numeric_constant::NC_COMPLEX; }
+ bool
+ is_invalid() const
+ { return this->classification_ == Numeric_constant::NC_INVALID; }
+
// Value retrievers. These will initialize the values as well as
// set them. GET_INT is only valid if IS_INT returns true, and
// likewise respectively.
mpfr_to_unsigned_long(const mpfr_t fval, unsigned long *val) const;
bool
- check_int_type(Integer_type*, bool, Location) const;
+ check_int_type(Integer_type*, bool, Location);
bool
check_float_type(Float_type*, bool, Location);