mirror of git://gcc.gnu.org/git/gcc.git
compiler: reject incorrect unsafe.Offsetof expressions.
The x.Field argument to Offsetof may not involve hidden dereferences of embedded pointer fields. Also correct uninitialized implicit_ field. From-SVN: r200221
This commit is contained in:
parent
a09f1a766b
commit
8259d36468
|
|
@ -6955,6 +6955,26 @@ Builtin_call_expression::do_lower(Gogo* gogo, Named_object* function,
|
||||||
return Expression::make_error(loc);
|
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())
|
if (this->is_constant())
|
||||||
{
|
{
|
||||||
Numeric_constant nc;
|
Numeric_constant nc;
|
||||||
|
|
|
||||||
|
|
@ -1872,7 +1872,7 @@ class Field_reference_expression : public Expression
|
||||||
Field_reference_expression(Expression* expr, unsigned int field_index,
|
Field_reference_expression(Expression* expr, unsigned int field_index,
|
||||||
Location location)
|
Location location)
|
||||||
: Expression(EXPRESSION_FIELD_REFERENCE, location),
|
: Expression(EXPRESSION_FIELD_REFERENCE, location),
|
||||||
expr_(expr), field_index_(field_index), called_fieldtrack_(false)
|
expr_(expr), field_index_(field_index), implicit_(false), called_fieldtrack_(false)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
// Return the struct expression.
|
// Return the struct expression.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue