| Submitter | Ian Taylor |
|---|---|
| Date | Oct. 8, 2010, 8:36 p.m. |
| Message ID | <mcrbp742zh7.fsf@google.com> |
| Download | mbox | patch |
| Permalink | /patch/67281/ |
| State | New |
| Headers | show |
Comments
On Fri, 8 Oct 2010, Ian Lance Taylor wrote: > This patch does two things. The first is that taking the slice of a > composite literal requires putting the composite literal on the heap, so > that the slice has something permanent to point to. The second is some > adjustments to #includes and names for the upcoming merge with gcc > mainline. Committed to gccgo branch. Out of interest, what is it you are adding toplev.h includes for? For the most part things have been moving *out* of toplev.c and toplev.h lately, and toplev.h includes have been removed from various source files; what's left in toplev.[ch] is a poorly-defined random mixture that could do with being better split up.
"Joseph S. Myers" <joseph@codesourcery.com> writes: > On Fri, 8 Oct 2010, Ian Lance Taylor wrote: > >> This patch does two things. The first is that taking the slice of a >> composite literal requires putting the composite literal on the heap, so >> that the slice has something permanent to point to. The second is some >> adjustments to #includes and names for the upcoming merge with gcc >> mainline. Committed to gccgo branch. > > Out of interest, what is it you are adding toplev.h includes for? For the > most part things have been moving *out* of toplev.c and toplev.h lately, > and toplev.h includes have been removed from various source files; what's > left in toplev.[ch] is a poorly-defined random mixture that could do with > being better split up. I'm using toplev.h for the declaration of rest_of_decl_compilation. Presumably the same reason that c-decl.c includes it. Ian
Patch
diff -r 426520ed103c go/expressions.cc --- a/go/expressions.cc Fri Oct 08 13:31:22 2010 -0700 +++ b/go/expressions.cc Fri Oct 08 13:34:52 2010 -0700 @@ -10,12 +10,14 @@ extern "C" { +#include "toplev.h" #include "intl.h" #include "tree.h" #include "gimple.h" #include "tree-iterator.h" #include "convert.h" #include "real.h" +#include "realmpfr.h" #include "tm_p.h" } @@ -131,7 +133,7 @@ void Expression::do_discarding_value() { - this->warn_unused_value(); + this->warn_about_unused_value(); } // This virtual function is called to export expressions. This will @@ -146,7 +148,7 @@ // Warn that the value of the expression is not used. void -Expression::warn_unused_value() +Expression::warn_about_unused_value() { warning_at(this->location(), OPT_Wunused_value, "value computed is not used"); } @@ -5179,7 +5181,7 @@ if (this->op_ == OPERATOR_OROR || this->op_ == OPERATOR_ANDAND) this->right_->discarding_value(); else - this->warn_unused_value(); + this->warn_about_unused_value(); } // Get type. @@ -9003,6 +9005,13 @@ Expression::make_array_index(Expression* array, Expression* start, Expression* end, source_location location) { + // Taking a slice of a composite literal requires moving the literal + // onto the heap. + if (end != NULL && array->is_composite_literal()) + { + array = Expression::make_heap_composite(array, location); + array = Expression::make_unary(OPERATOR_MULT, array, location); + } return new Array_index_expression(array, start, end, location); } diff -r 426520ed103c go/expressions.h --- a/go/expressions.h Fri Oct 08 13:31:22 2010 -0700 +++ b/go/expressions.h Fri Oct 08 13:34:52 2010 -0700 @@ -682,7 +682,7 @@ // For children to call to warn about an unused value. void - warn_unused_value(); + warn_about_unused_value(); // For children to call when they detect that they are in error. void