diff mbox

Go patch committed: Don't crash on append with a single argument

Message ID CAOyqgcVzCV-kVmz6J4BgzMfVw6Ti6U6zKW-X5H5z_2a8c+HiAA@mail.gmail.com
State New
Headers show

Commit Message

Ian Lance Taylor Dec. 17, 2014, 1:04 a.m. UTC
Gccgo was crashing when a program called append with a single
argument.  Doing this doesn't make sense, but of course the compiler
should not crash.  The crash was due to the code passing nil as the
second argument, then converting that to a slice composite literal.  A
slice composite literal needs a type, and this type was created too
late for the type descriptor to be created.  This patch finesses the
issue by creating a slice value with a nil pointer instead.  The test
case for this is https://go-review.googlesource.com/#/c/1692/ .
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.

Ian
diff mbox

Patch

diff -r b7c3f882d939 go/expressions.cc
--- a/go/expressions.cc	Tue Dec 16 14:50:50 2014 -0800
+++ b/go/expressions.cc	Tue Dec 16 16:41:23 2014 -0800
@@ -6878,7 +6878,11 @@ 
            ++pa)
         {
           if ((*pa)->is_nil_expression())
-            *pa = Expression::make_slice_composite_literal(at, NULL, loc);
+	    {
+	      Expression* nil = Expression::make_nil(loc);
+	      Expression* zero = Expression::make_integer_ul(0, NULL, loc);
+	      *pa = Expression::make_slice_value(at, nil, zero, zero, loc);
+	    }
           if (!(*pa)->is_variable())
             {
               Temporary_statement* temp =
@@ -14087,7 +14091,8 @@ 
 int
 Slice_value_expression::do_traverse(Traverse* traverse)
 {
-  if (Expression::traverse(&this->valptr_, traverse) == TRAVERSE_EXIT
+  if (Type::traverse(this->type_, traverse) == TRAVERSE_EXIT
+      || Expression::traverse(&this->valptr_, traverse) == TRAVERSE_EXIT
       || Expression::traverse(&this->len_, traverse) == TRAVERSE_EXIT
       || Expression::traverse(&this->cap_, traverse) == TRAVERSE_EXIT)
     return TRAVERSE_EXIT;