aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/gofrontend/expressions.h
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2019-03-15 04:34:43 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2019-03-15 04:34:43 +0000
commitb1403b691a24fae2a96fa7ce5b93c3395e7bfd05 (patch)
tree9000ae815c21bbe19c77f3316301fd75964c6e93 /gcc/go/gofrontend/expressions.h
parent928499cfeee9cba7cc63e4c8547f88306d8d45fb (diff)
downloadgcc-b1403b691a24fae2a96fa7ce5b93c3395e7bfd05.zip
gcc-b1403b691a24fae2a96fa7ce5b93c3395e7bfd05.tar.gz
gcc-b1403b691a24fae2a96fa7ce5b93c3395e7bfd05.tar.bz2
compiler: eliminate bound checks in append expression
The compiler generates two array index expressions when lowering an append expression. Currently they generate bound checks. Bound checks are not necessary in this case, as we know the slice has, or will grow to, enough length and capacity. Eliminate them. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/166817 From-SVN: r269699
Diffstat (limited to 'gcc/go/gofrontend/expressions.h')
-rw-r--r--gcc/go/gofrontend/expressions.h28
1 files changed, 18 insertions, 10 deletions
diff --git a/gcc/go/gofrontend/expressions.h b/gcc/go/gofrontend/expressions.h
index 5d61b69..c521d9b 100644
--- a/gcc/go/gofrontend/expressions.h
+++ b/gcc/go/gofrontend/expressions.h
@@ -2854,7 +2854,7 @@ class Array_index_expression : public Expression
Expression* end, Expression* cap, Location location)
: Expression(EXPRESSION_ARRAY_INDEX, location),
array_(array), start_(start), end_(end), cap_(cap), type_(NULL),
- is_lvalue_(false)
+ is_lvalue_(false), needs_bounds_check_(true)
{ }
// Return the array.
@@ -2898,6 +2898,10 @@ class Array_index_expression : public Expression
set_is_lvalue()
{ this->is_lvalue_ = true; }
+ void
+ set_needs_bounds_check(bool b)
+ { this->needs_bounds_check_ = b; }
+
protected:
int
do_traverse(Traverse*);
@@ -2917,15 +2921,17 @@ class Array_index_expression : public Expression
Expression*
do_copy()
{
- return Expression::make_array_index(this->array_->copy(),
- this->start_->copy(),
- (this->end_ == NULL
- ? NULL
- : this->end_->copy()),
- (this->cap_ == NULL
- ? NULL
- : this->cap_->copy()),
- this->location());
+ Expression* ret = Expression::make_array_index(this->array_->copy(),
+ this->start_->copy(),
+ (this->end_ == NULL
+ ? NULL
+ : this->end_->copy()),
+ (this->cap_ == NULL
+ ? NULL
+ : this->cap_->copy()),
+ this->location());
+ ret->array_index_expression()->set_needs_bounds_check(this->needs_bounds_check_);
+ return ret;
}
bool
@@ -2962,6 +2968,8 @@ class Array_index_expression : public Expression
Type* type_;
// Whether expr appears in an lvalue context.
bool is_lvalue_;
+ // Whether bounds check is needed.
+ bool needs_bounds_check_;
};
// A string index. This is used for both indexing and slicing.