]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: fix compiler crash on recursive types
authorMatthew Dempsky <mdempsky@google.com>
Mon, 18 Sep 2017 18:54:03 +0000 (11:54 -0700)
committerMatthew Dempsky <mdempsky@google.com>
Mon, 18 Sep 2017 21:49:43 +0000 (21:49 +0000)
By setting both a valid size and alignment for broken recursive types,
we can appease some more safety checks and prevent compiler crashes.

Fixes #21882.

Change-Id: Ibaa137d8aa2c2a9d521462f144d7016c4abfd6e7
Reviewed-on: https://go-review.googlesource.com/64430
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/cmd/compile/internal/gc/align.go
test/fixedbugs/issue21882.go [new file with mode: 0644]

index f29c587877bf9067c2d58a46b6149486059f14c6..285d31dc6c6eeecbeefd5c50dc849bb986b7a776 100644 (file)
@@ -176,6 +176,7 @@ func dowidth(t *types.Type) {
                }
 
                t.Width = 0
+               t.Align = 1
                return
        }
 
diff --git a/test/fixedbugs/issue21882.go b/test/fixedbugs/issue21882.go
new file mode 100644 (file)
index 0000000..f77e046
--- /dev/null
@@ -0,0 +1,9 @@
+// errorcheck
+
+// Copyright 2017 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
+
+type T [2]T // ERROR "invalid recursive type"