From fdcef314bcb0728d883cd87d6950d85217e82755 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 7 Jan 2019 21:44:06 +0000 Subject: compiler: move slice construction to callers of makeslice This is the gccgo version of https://golang.org/cl/141822: Only return a pointer p to the new slices backing array from makeslice. Makeslice callers then construct sliceheader{p, len, cap} explictly instead of makeslice returning the slice. This change caused the GCC backend to break the runtime/pprof test by merging together the identical functions allocateReflectTransient and allocateTransient2M. This caused the traceback to be other than expected. Fix that by making the functions not identical. This is a step toward updating libgo to the Go1.12beta1 release. Reviewed-on: https://go-review.googlesource.com/c/155937 From-SVN: r267660 --- gcc/go/gofrontend/expressions.h | 57 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'gcc/go/gofrontend/expressions.h') diff --git a/gcc/go/gofrontend/expressions.h b/gcc/go/gofrontend/expressions.h index a18322c..db40d8d 100644 --- a/gcc/go/gofrontend/expressions.h +++ b/gcc/go/gofrontend/expressions.h @@ -61,6 +61,7 @@ class Map_construction_expression; class Type_guard_expression; class Heap_expression; class Receive_expression; +class Slice_value_expression; class Conditional_expression; class Compound_expression; class Numeric_constant; @@ -841,6 +842,12 @@ class Expression receive_expression() { return this->convert(); } + // If this is a slice value expression, return the Slice_valiue_expression + // structure. Otherwise, return NULL. + Slice_value_expression* + slice_value_expression() + { return this->convert(); } + // If this is a conditional expression, return the Conditional_expression // structure. Otherwise, return NULL. Conditional_expression* @@ -3955,6 +3962,56 @@ class Receive_expression : public Expression Temporary_statement* temp_receiver_; }; +// An expression that represents a slice value: a struct with value pointer, +// length, and capacity fields. + +class Slice_value_expression : public Expression +{ + public: + Slice_value_expression(Type* type, Expression* valmem, Expression* len, + Expression* cap, Location location) + : Expression(EXPRESSION_SLICE_VALUE, location), + type_(type), valmem_(valmem), len_(len), cap_(cap) + { } + + // The memory holding the values in the slice. The type should be a + // pointer to the element value of the slice. + Expression* + valmem() const + { return this->valmem_; } + + protected: + int + do_traverse(Traverse*); + + Type* + do_type() + { return this->type_; } + + void + do_determine_type(const Type_context*) + { } + + Expression* + do_copy(); + + Bexpression* + do_get_backend(Translate_context* context); + + void + do_dump_expression(Ast_dump_context*) const; + + private: + // The type of the slice value. + Type* type_; + // The memory holding the values in the slice. + Expression* valmem_; + // The length of the slice. + Expression* len_; + // The capacity of the slice. + Expression* cap_; +}; + // Conditional expressions. class Conditional_expression : public Expression -- cgit v1.1