compiler: guard against implicit double pointer indirection
authorIan Lance Taylor <ian@gcc.gnu.org>
Sat, 9 Sep 2017 06:01:35 +0000 (06:01 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Sat, 9 Sep 2017 06:01:35 +0000 (06:01 +0000)
    The code that lowers field references can sometimes introduce a double
    pointer indirection in cases where it is not/safe appropriate. For
    example, in

            var p **struct { f int }
            p.f = 0

    the assignment LHS was being incorrectly lowered to (*(*p)).f.
    Detect this situation and issue an error.

    Fixes golang/go#21770

    Reviewed-on: https://go-review.googlesource.com/62330

From-SVN: r251918

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/types.cc

index edcea96094c85431eddfb0755fdf2df93aff9794..9576230ee582141a854881308559baa23db13aba 100644 (file)
@@ -1,4 +1,4 @@
-9d0d5c03a8086f5dd3a23e910abd6e470196973c
+52ebad939927e6cbfb48dd277cef8db451e36533
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index 4d923733667ff9d45338e87b892918ae3b194bac..cde1408bbf33442933cb7b0574d5ce85bf469ba3 100644 (file)
@@ -11829,6 +11829,12 @@ Type::bind_field_or_method(Gogo* gogo, const Type* type, Expression* expr,
          go_assert(st != NULL);
          if (type->struct_type() == NULL)
            {
+              if (dereferenced)
+                {
+                  go_error_at(location, "pointer type has no field %qs",
+                              Gogo::message_name(name).c_str());
+                  return Expression::make_error(location);
+                }
              go_assert(type->points_to() != NULL);
              expr = Expression::make_unary(OPERATOR_MULT, expr,
                                            location);