aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2020-11-18 12:08:59 -0800
committerMatthew Dempsky <mdempsky@google.com>2020-11-18 22:12:57 +0000
commit5b0ec1a6ac0e644c89940e0fe5f79863ad2eafaa (patch)
treeb9f558769fb79aa83efe9c0283fdd71ddb69ab66 /test
parentb4f3d52f6a90aa520799f836e5951d5cf65f7fe4 (diff)
downloadgo-5b0ec1a6ac0e644c89940e0fe5f79863ad2eafaa.tar.gz
go-5b0ec1a6ac0e644c89940e0fe5f79863ad2eafaa.zip
cmd/compile: fix panic in field tracking logic
Within the frontend, we generally don't guarantee uniqueness of anonymous types. For example, each struct type literal gets represented by its own types.Type instance. However, the field tracking code was using the struct type as a map key. This broke in golang.org/cl/256457, because that CL started changing the inlined parameter variables from using the types.Type of the declared parameter to that of the call site argument. These are always identical types (e.g., types.Identical would report true), but they can be different pointer values, causing the map lookup to fail. The easiest fix is to simply get rid of the map and instead use Node.Opt for tracking the types.Field. To mitigate against more latent field tracking failures (e.g., if any other code were to start trying to use Opt on ODOT/ODOTPTR fields), we store this field unconditionally. I also expect having the types.Field will be useful to other frontend code in the future. Finally, to make it easier to test field tracking without having to run make.bash with GOEXPERIMENT=fieldtrack, this commit adds a -d=fieldtrack flag as an alternative way to enable field tracking within the compiler. See also #42681. Fixes #42686. Change-Id: I6923d206d5e2cab1e6798cba36cae96c1eeaea55 Reviewed-on: https://go-review.googlesource.com/c/go/+/271217 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Trust: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/fixedbugs/issue42686.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/test/fixedbugs/issue42686.go b/test/fixedbugs/issue42686.go
new file mode 100644
index 0000000000..962bdd35cb
--- /dev/null
+++ b/test/fixedbugs/issue42686.go
@@ -0,0 +1,11 @@
+// compile -d=fieldtrack
+
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package p
+
+func a(x struct{ f int }) { _ = x.f }
+
+func b() { a(struct{ f int }{}) }