From fc4f90f0c8eca75fb90c736476360584f68d7ef9 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 28 Aug 2019 18:27:30 +0000 Subject: compiler, runtime: provide index information on bounds check failure This implements https://golang.org/cl/161477 in the gofrontend. Updates golang/go#30116 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/191881 From-SVN: r274998 --- gcc/go/gofrontend/expressions.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'gcc/go/gofrontend/expressions.h') diff --git a/gcc/go/gofrontend/expressions.h b/gcc/go/gofrontend/expressions.h index 3b65e7a..4c743da 100644 --- a/gcc/go/gofrontend/expressions.h +++ b/gcc/go/gofrontend/expressions.h @@ -1059,10 +1059,11 @@ class Expression static Expression* import_expression(Import_expression*, Location); - // Return an expression which checks that VAL, of arbitrary integer type, - // is non-negative and is not more than the maximum integer value. - static Expression* - check_bounds(Expression* val, Location); + // Insert bounds checks for an index expression. + static void + check_bounds(Expression* val, Operator, Expression* bound, Runtime::Function, + Runtime::Function, Runtime::Function, Runtime::Function, + Statement_inserter*, Location); // Return an expression for constructing a direct interface type from a // pointer. @@ -2998,7 +2999,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), needs_bounds_check_(true) + is_lvalue_(false), needs_bounds_check_(true), is_flattened_(false) { } // Return the array. @@ -3121,6 +3122,8 @@ class Array_index_expression : public Expression bool is_lvalue_; // Whether bounds check is needed. bool needs_bounds_check_; + // Whether this has already been flattened. + bool is_flattened_; }; // A string index. This is used for both indexing and slicing. @@ -3131,7 +3134,7 @@ class String_index_expression : public Expression String_index_expression(Expression* string, Expression* start, Expression* end, Location location) : Expression(EXPRESSION_STRING_INDEX, location), - string_(string), start_(start), end_(end) + string_(string), start_(start), end_(end), is_flattened_(false) { } // Return the string being indexed. @@ -3203,6 +3206,8 @@ class String_index_expression : public Expression // The end index of a slice. This may be NULL for a single index, // or it may be a nil expression for the length of the string. Expression* end_; + // Whether this has already been flattened. + bool is_flattened_; }; // An index into a map. -- cgit v1.1