This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Go patch committed: Use backend interface for struct field offsets
- From: Ian Lance Taylor <iant at google dot com>
- To: gcc-patches at gcc dot gnu dot org, gofrontend-dev at googlegroups dot com
- Date: Mon, 05 May 2014 13:55:04 -0400
- Subject: Go patch committed: Use backend interface for struct field offsets
- Authentication-results: sourceware.org; auth=none
This patch by Chris Manghane changes the Go frontend to use the backend
interface for struct field offsets. Bootstrapped and ran Go testsuite
on x86_64-unknown-linux-gnu. Committed to mainline.
Ian
diff -r d87cfc273ffc go/expressions.cc
--- a/go/expressions.cc Mon May 05 13:21:55 2014 -0400
+++ b/go/expressions.cc Mon May 05 13:39:45 2014 -0400
@@ -14815,28 +14815,27 @@
tree
Struct_field_offset_expression::do_get_tree(Translate_context* context)
{
- tree type_tree = type_to_tree(this->type_->get_backend(context->gogo()));
- if (type_tree == error_mark_node)
- return error_mark_node;
-
- tree val_type_tree = type_to_tree(this->type()->get_backend(context->gogo()));
- go_assert(val_type_tree != error_mark_node);
-
const Struct_field_list* fields = this->type_->fields();
- tree struct_field_tree = TYPE_FIELDS(type_tree);
Struct_field_list::const_iterator p;
+ unsigned i = 0;
for (p = fields->begin();
p != fields->end();
- ++p, struct_field_tree = DECL_CHAIN(struct_field_tree))
- {
- go_assert(struct_field_tree != NULL_TREE);
- if (&*p == this->field_)
- break;
- }
+ ++p, ++i)
+ if (&*p == this->field_)
+ break;
go_assert(&*p == this->field_);
- return fold_convert_loc(BUILTINS_LOCATION, val_type_tree,
- byte_position(struct_field_tree));
+ Gogo* gogo = context->gogo();
+ Btype* btype = this->type_->get_backend(gogo);
+
+ size_t offset = gogo->backend()->type_field_offset(btype, i);
+ mpz_t offsetval;
+ mpz_init_set_ui(offsetval, offset);
+ Type* uptr_type = Type::lookup_integer_type("uintptr");
+ Expression* ret = Expression::make_integer(&offsetval, uptr_type,
+ Linemap::predeclared_location());
+ mpz_clear(offsetval);
+ return ret->get_tree(context);
}
// Dump ast representation for a struct field offset expression.