compiler: report error for ++/-- applied to a non-numeric type
authorIan Lance Taylor <ian@gcc.gnu.org>
Tue, 21 Nov 2017 06:14:32 +0000 (06:14 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Tue, 21 Nov 2017 06:14:32 +0000 (06:14 +0000)
    This avoids a compiler crash.

    Fixes GCC PR 83071.

    Reviewed-on: https://go-review.googlesource.com/78875

From-SVN: r254983

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/statements.cc

index 4832c7829465e76057722b3544830327c488dd94..ed351c032ed3bd39fd9217f66225a6fe07f390b4 100644 (file)
@@ -1,4 +1,4 @@
-cb5dc1ce98857884a2215c461dd1d7de530f9f5e
+5485b3faed476f6d051833d1790b5f77be9d1efc
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index b22f690b3d6eac7ace6373175933ce1c5f81a3bf..e97798008ea6408c234390156646c2b624fc243f 100644 (file)
@@ -1826,6 +1826,11 @@ Statement*
 Inc_dec_statement::do_lower(Gogo*, Named_object*, Block*, Statement_inserter*)
 {
   Location loc = this->location();
+  if (!this->expr_->type()->is_numeric_type())
+    {
+      this->report_error("increment or decrement of non-numeric type");
+      return Statement::make_error_statement(loc);
+    }
   Expression* oexpr = Expression::make_integer_ul(1, this->expr_->type(), loc);
   Operator op = this->is_inc_ ? OPERATOR_PLUSEQ : OPERATOR_MINUSEQ;
   return Statement::make_assignment_operation(op, this->expr_, oexpr, loc);