aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/gofrontend/expressions.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/go/gofrontend/expressions.cc')
-rw-r--r--gcc/go/gofrontend/expressions.cc20
1 files changed, 20 insertions, 0 deletions
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 9c1efb3..adadfbb 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -6955,6 +6955,26 @@ Builtin_call_expression::do_lower(Gogo* gogo, Named_object* function,
return Expression::make_error(loc);
}
+ if (this->code_ == BUILTIN_OFFSETOF)
+ {
+ Expression* arg = this->one_arg();
+ Field_reference_expression* farg = arg->field_reference_expression();
+ while (farg != NULL)
+ {
+ if (!farg->implicit())
+ break;
+ // When the selector refers to an embedded field,
+ // it must not be reached through pointer indirections.
+ if (farg->expr()->deref() != farg->expr())
+ {
+ this->report_error(_("argument of Offsetof implies indirection of an embedded field"));
+ return this;
+ }
+ // Go up until we reach the original base.
+ farg = farg->expr()->field_reference_expression();
+ }
+ }
+
if (this->is_constant())
{
Numeric_constant nc;