compiler: guard against implicit double pointer indirection
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
Change-Id: I350e0696e0aa7032114797fe21dc54faa0a44933
Reviewed-on: https://go-review.googlesource.com/62330
Reviewed-by: Ian Lance Taylor <iant@golang.org>
diff --git a/go/types.cc b/go/types.cc
index 4d92373..cde1408 100644
--- a/go/types.cc
+++ b/go/types.cc
@@ -11829,6 +11829,12 @@
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);