diff mbox

[gccgo] Don't get confused by floating point array length

Message ID mcrk4n6cuev.fsf@google.com
State New
Headers show

Commit Message

Ian Lance Taylor Aug. 31, 2010, 10:02 p.m. UTC
Go's untyped constants mean that you can use a floating point number as
an array length, as long as it has an integral value.  That works fine,
but some of the tree code wound up using a floating point constant
unexpectedly, leading to a compiler crash.  This patch fixes the
problem.  Committed to gccgo branch.

Ian
diff mbox

Patch

Index: gcc/go/Make-lang.in
===================================================================
--- gcc/go/Make-lang.in	(revision 163703)
+++ gcc/go/Make-lang.in	(revision 163704)
@@ -176,6 +176,7 @@  go/statements.o: go/statements.cc $(GO_S
 	$(GO_C_H) $(GO_TYPES_H) $(GO_EXPRESSIONS_H) $(GO_GOGO_H) \
 	$(GO_STATEMENTS_H)
 go/types.o: go/types.cc $(GO_SYSTEM_H) intl.h $(TREE_H) $(GIMPLE_H) \
-	$(REAL_H) $(GO_C_H) $(GO_GOGO_H) go/operator.h $(GO_EXPRESSIONS_H) \
-	$(GO_STATEMENTS_H) go/export.h $(GO_IMPORT_H) $(GO_TYPES_H)
+	$(REAL_H) convert.h $(GO_C_H) $(GO_GOGO_H) go/operator.h \
+	$(GO_EXPRESSIONS_H) $(GO_STATEMENTS_H) go/export.h $(GO_IMPORT_H) \
+	$(GO_TYPES_H)
 go/unsafe.o: go/unsafe.cc $(GO_SYSTEM_H) $(GO_TYPES_H) $(GO_GOGO_H)
Index: gcc/go/types.cc
===================================================================
--- gcc/go/types.cc	(revision 163703)
+++ gcc/go/types.cc	(revision 163704)
@@ -16,6 +16,7 @@  extern "C"
 #include "tree.h"
 #include "gimple.h"
 #include "real.h"
+#include "convert.h"
 }
 
 #include "go-c.h"
@@ -3438,7 +3439,9 @@  Array_type::get_length_tree(Gogo* gogo)
 	  // Make up a translation context for the array length
 	  // expression.  FIXME: This won't work in general.
 	  Translate_context context(gogo, NULL, NULL, NULL_TREE);
-	  this->length_tree_ = save_expr(this->length_->get_tree(&context));
+	  tree len = this->length_->get_tree(&context);
+	  len = convert_to_integer(integer_type_node, len);
+	  this->length_tree_ = save_expr(len);
 	}
     }
   return this->length_tree_;