]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
compiler: Better error message of unsafe.Offsetof(method value).
authorIan Lance Taylor <ian@gcc.gnu.org>
Fri, 11 Oct 2013 18:10:03 +0000 (18:10 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Fri, 11 Oct 2013 18:10:03 +0000 (18:10 +0000)
From-SVN: r203454

gcc/go/gofrontend/expressions.cc

index 06c34297a5377ff2d244a5223c1343141595bce2..258953f205ac5e77c70f37ef9dbc0c65214a867a 100644 (file)
@@ -7253,6 +7253,15 @@ Builtin_call_expression::do_lower(Gogo* gogo, Named_object* function,
   if (this->code_ == BUILTIN_OFFSETOF)
     {
       Expression* arg = this->one_arg();
+
+      if (arg->bound_method_expression() != NULL
+         || arg->interface_field_reference_expression() != NULL)
+       {
+         this->report_error(_("invalid use of method value as argument "
+                              "of Offsetof"));
+         return this;
+       }
+
       Field_reference_expression* farg = arg->field_reference_expression();
       while (farg != NULL)
        {
@@ -7262,7 +7271,8 @@ Builtin_call_expression::do_lower(Gogo* gogo, Named_object* function,
          // 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"));
+             this->report_error(_("argument of Offsetof implies "
+                                  "indirection of an embedded field"));
              return this;
            }
          // Go up until we reach the original base.
@@ -7672,6 +7682,8 @@ Find_call_expression::expression(Expression** pexpr)
 bool
 Builtin_call_expression::do_is_constant() const
 {
+  if (this->is_error_expression())
+    return true;
   switch (this->code_)
     {
     case BUILTIN_LEN: