diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-06-26 22:42:35 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2013-06-26 22:42:35 +0000 |
commit | 69908ca8b6af97880f4c4e4653dfc9a51a7be3d6 (patch) | |
tree | 80c3c4288b5dd0d2a516d77d36fc58e905b7d0de /gcc/go | |
parent | 9e2166298aa8a296540b5f72b135f9cf989d8671 (diff) | |
download | gcc-69908ca8b6af97880f4c4e4653dfc9a51a7be3d6.zip gcc-69908ca8b6af97880f4c4e4653dfc9a51a7be3d6.tar.gz gcc-69908ca8b6af97880f4c4e4653dfc9a51a7be3d6.tar.bz2 |
compiler: reject integer division by zero constant.
From-SVN: r200436
Diffstat (limited to 'gcc/go')
-rw-r--r-- | gcc/go/gofrontend/expressions.cc | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc index 9085a46..2b60d90 100644 --- a/gcc/go/gofrontend/expressions.cc +++ b/gcc/go/gofrontend/expressions.cc @@ -5848,6 +5848,20 @@ Binary_expression::do_check_types(Gogo*) this->set_is_error(); return; } + if (this->op_ == OPERATOR_DIV || this->op_ == OPERATOR_MOD) + { + // Division by a zero integer constant is an error. + Numeric_constant rconst; + unsigned long rval; + if (left_type->integer_type() != NULL + && this->right_->numeric_constant_value(&rconst) + && rconst.to_unsigned_long(&rval) == Numeric_constant::NC_UL_VALID + && rval == 0) + { + this->report_error(_("integer division by zero")); + return; + } + } } else { |