This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Go patch committed: Avoid crash, fix *&x when x is not addressable


This patch to the Go frontend avoids a compiler crash on invalid code.
It also fixes the case of *&x when x is not addressable--the expression
was being converted to x without checking, meaning that the compiler
would accept invalid code.  Finally, an error message is fixed to have
correct punctuation.  This is all from PR 60288.  Bootstrapped and ran
Go testsuite on x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

diff -r 638c5b3ab8cb go/expressions.cc
--- a/go/expressions.cc	Mon Feb 17 12:45:42 2014 -0800
+++ b/go/expressions.cc	Thu Feb 20 07:15:48 2014 -0800
@@ -3792,6 +3792,12 @@
 	      if (e == expr)
 		{
 		  // *&x == x.
+		  if (!ue->expr_->is_addressable() && !ue->create_temp_)
+		    {
+		      error_at(ue->location(),
+			       "invalid operand for unary %<&%>");
+		      this->set_is_error();
+		    }
 		  return ue->expr_;
 		}
 	      ue->set_does_not_escape();
@@ -3828,6 +3834,9 @@
 Unary_expression::do_flatten(Gogo* gogo, Named_object*,
                              Statement_inserter* inserter)
 {
+  if (this->is_error_expression() || this->expr_->is_error_expression())
+    return Expression::make_error(this->location());
+
   Location location = this->location();
   if (this->op_ == OPERATOR_MULT
       && !this->expr_->is_variable())
@@ -4167,7 +4176,10 @@
       if (!this->expr_->is_addressable())
 	{
 	  if (!this->create_temp_)
-	    this->report_error(_("invalid operand for unary %<&%>"));
+	    {
+	      error_at(this->location(), "invalid operand for unary %<&%>");
+	      this->set_is_error();
+	    }
 	}
       else
         {

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]