aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2012-02-02 22:23:10 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2012-02-02 22:23:10 +0000
commitb6422b3755f39ebc4f942c5f92bd242aee948539 (patch)
tree40abcc344adc9a14c3dc1b9b4b79bd518255e2dc /gcc
parent7de7ae1841e599746f1974ac507bb1d51483c47c (diff)
downloadgcc-b6422b3755f39ebc4f942c5f92bd242aee948539.zip
gcc-b6422b3755f39ebc4f942c5f92bd242aee948539.tar.gz
gcc-b6422b3755f39ebc4f942c5f92bd242aee948539.tar.bz2
compiler: Compare slice start and end with cap, not len.
From-SVN: r183851
Diffstat (limited to 'gcc')
-rw-r--r--gcc/go/gofrontend/expressions.cc38
-rw-r--r--gcc/go/gofrontend/types.cc3
2 files changed, 27 insertions, 14 deletions
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index c3b43cd..f906b22 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -10649,11 +10649,28 @@ Array_index_expression::do_get_tree(Translate_context* context)
if (array_type->length() == NULL && !DECL_P(array_tree))
array_tree = save_expr(array_tree);
- tree length_tree = array_type->length_tree(gogo, array_tree);
- if (length_tree == error_mark_node)
- return error_mark_node;
- length_tree = save_expr(length_tree);
- tree length_type = TREE_TYPE(length_tree);
+
+ tree length_tree = NULL_TREE;
+ if (this->end_ == NULL || this->end_->is_nil_expression())
+ {
+ length_tree = array_type->length_tree(gogo, array_tree);
+ if (length_tree == error_mark_node)
+ return error_mark_node;
+ length_tree = save_expr(length_tree);
+ }
+
+ tree capacity_tree = NULL_TREE;
+ if (this->end_ != NULL)
+ {
+ capacity_tree = array_type->capacity_tree(gogo, array_tree);
+ if (capacity_tree == error_mark_node)
+ return error_mark_node;
+ capacity_tree = save_expr(capacity_tree);
+ }
+
+ tree length_type = (length_tree != NULL_TREE
+ ? TREE_TYPE(length_tree)
+ : TREE_TYPE(capacity_tree));
tree bad_index = boolean_false_node;
@@ -10676,7 +10693,9 @@ Array_index_expression::do_get_tree(Translate_context* context)
? GE_EXPR
: GT_EXPR),
boolean_type_node, start_tree,
- length_tree));
+ (this->end_ == NULL
+ ? length_tree
+ : capacity_tree)));
int code = (array_type->length() != NULL
? (this->end_ == NULL
@@ -10723,12 +10742,6 @@ Array_index_expression::do_get_tree(Translate_context* context)
// Array slice.
- tree capacity_tree = array_type->capacity_tree(gogo, array_tree);
- if (capacity_tree == error_mark_node)
- return error_mark_node;
- capacity_tree = fold_convert_loc(loc.gcc_location(), length_type,
- capacity_tree);
-
tree end_tree;
if (this->end_->is_nil_expression())
end_tree = length_tree;
@@ -10747,7 +10760,6 @@ Array_index_expression::do_get_tree(Translate_context* context)
end_tree = fold_convert_loc(loc.gcc_location(), length_type, end_tree);
- capacity_tree = save_expr(capacity_tree);
tree bad_end = fold_build2_loc(loc.gcc_location(), TRUTH_OR_EXPR,
boolean_type_node,
fold_build2_loc(loc.gcc_location(),
diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc
index 4020399..0bbe3c5 100644
--- a/gcc/go/gofrontend/types.cc
+++ b/gcc/go/gofrontend/types.cc
@@ -5416,7 +5416,8 @@ tree
Array_type::capacity_tree(Gogo* gogo, tree array)
{
if (this->length_ != NULL)
- return omit_one_operand(sizetype, this->get_length_tree(gogo), array);
+ return omit_one_operand(integer_type_node, this->get_length_tree(gogo),
+ array);
// This is an open array. We need to read the capacity field.