From c216ae80c965acb9641d94d5f58c206bd0cf7d66 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Mon, 19 Oct 2020 14:14:40 -0700 Subject: [PATCH] cmd/compile: fix ICE in reporting of invalid recursive types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit asNode(t.Nod).Name.Param will be nil for builtin types (i.e., the universal predeclared types and unsafe.Pointer). These types can't be part of a cycle anyway, so we can just skip them. Fixes #42075. Change-Id: Ic7a44de65c6bfd16936545dee25e36de8850acf3 Reviewed-on: https://go-review.googlesource.com/c/go/+/263717 Trust: Matthew Dempsky Trust: Daniel Martí Reviewed-by: Daniel Martí --- src/cmd/compile/internal/gc/align.go | 2 +- test/fixedbugs/issue42075.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/fixedbugs/issue42075.go diff --git a/src/cmd/compile/internal/gc/align.go b/src/cmd/compile/internal/gc/align.go index 5af403afa3..4bc454df22 100644 --- a/src/cmd/compile/internal/gc/align.go +++ b/src/cmd/compile/internal/gc/align.go @@ -199,7 +199,7 @@ func findTypeLoop(t *types.Type, path *[]*types.Type) bool { } *path = append(*path, t) - if findTypeLoop(asNode(t.Nod).Name.Param.Ntype.Type, path) { + if p := asNode(t.Nod).Name.Param; p != nil && findTypeLoop(p.Ntype.Type, path) { return true } *path = (*path)[:len(*path)-1] diff --git a/test/fixedbugs/issue42075.go b/test/fixedbugs/issue42075.go new file mode 100644 index 0000000000..af85fb281d --- /dev/null +++ b/test/fixedbugs/issue42075.go @@ -0,0 +1,16 @@ +// errorcheck + +// 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 + +import "unsafe" + +type T struct { // ERROR "recursive type" + x int + p unsafe.Pointer + + f T +}