Patchwork Go patch committed: Avoid reading bogus field

login
register
mail settings
Submitter Ian Taylor
Date March 28, 2014, 5:20 a.m.
Message ID <mcrlhvu291l.fsf@iant-glaptop.roam.corp.google.com>
Download mbox | patch
Permalink /patch/334586/
State New
Headers show

Comments

Ian Taylor - March 28, 2014, 5:20 a.m.
PR 59545 points out that there is a case where the Go frontend reads an
invalid value from a class field.  This happens because of an incorrect
static_cast.  This patch fixes the problem to only use the static_cast
when it is valid.  Bootstrapped and ran Go tests on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Patch

diff -r 55fb8756d889 go/expressions.cc
--- a/go/expressions.cc	Thu Mar 27 14:22:49 2014 -0700
+++ b/go/expressions.cc	Thu Mar 27 22:11:25 2014 -0700
@@ -4163,8 +4163,12 @@ 
 
           go_assert(!this->expr_->is_composite_literal()
                     || this->expr_->is_immutable());
-          Unary_expression* ue = static_cast<Unary_expression*>(this->expr_);
-          go_assert(ue == NULL || ue->op() != OPERATOR_AND);
+	  if (this->expr_->classification() == EXPRESSION_UNARY)
+	    {
+	      Unary_expression* ue =
+		static_cast<Unary_expression*>(this->expr_);
+	      go_assert(ue->op() != OPERATOR_AND);
+	    }
 	}
 
       // Build a decl for a constant constructor.