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]

[gccgo] Taking slice of composite literal puts literal on heap


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.

Ian

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

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