diff mbox series

Go patch committed: report error for ++/-- applied to a non-numeric type

Message ID CAOyqgcX7GA0MVL8xNgNRcCXvDogeiL1ng+sHwAYNfWVHq3ueJw@mail.gmail.com
State New
Headers show
Series Go patch committed: report error for ++/-- applied to a non-numeric type | expand

Commit Message

Ian Lance Taylor Nov. 21, 2017, 6:14 a.m. UTC
This patch to the Go frontend reports an error when ++ or -- is used
with a non-numeric type.  This avoids a later compiler crash.  This
fixes GCC PR 83071.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian
diff mbox series

Patch

Index: gcc/go/gofrontend/MERGE
===================================================================
--- gcc/go/gofrontend/MERGE	(revision 254748)
+++ gcc/go/gofrontend/MERGE	(working copy)
@@ -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: gcc/go/gofrontend/statements.cc
===================================================================
--- gcc/go/gofrontend/statements.cc	(revision 254748)
+++ gcc/go/gofrontend/statements.cc	(working copy)
@@ -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);