mirror of
https://github.com/golang/go
synced 2024-11-14 06:30:22 -07:00
cmd/compile: silence unnecessary unsafe error
If n.Type==nil after typechecking, then we should have already reported a more useful error somewhere else. Just return 0 in evalunsafe without trying to do anything else that's likely to cause problems. Also, further split out issue7525.go into more test files, because cmd/compile reports at most one typechecking loop per compilation unit. Fixes #22351. Change-Id: I3ebf505f72c48fcbfef5ec915606224406026597 Reviewed-on: https://go-review.googlesource.com/72251 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
54fa10a98e
commit
efa9efe8e4
@ -12,7 +12,6 @@ func evalunsafe(n *Node) int64 {
|
|||||||
n.Left = defaultlit(n.Left, nil)
|
n.Left = defaultlit(n.Left, nil)
|
||||||
tr := n.Left.Type
|
tr := n.Left.Type
|
||||||
if tr == nil {
|
if tr == nil {
|
||||||
yyerror("invalid expression %v", n)
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
dowidth(tr)
|
dowidth(tr)
|
||||||
@ -35,6 +34,9 @@ func evalunsafe(n *Node) int64 {
|
|||||||
base := n.Left.Left
|
base := n.Left.Left
|
||||||
|
|
||||||
n.Left = typecheck(n.Left, Erv)
|
n.Left = typecheck(n.Left, Erv)
|
||||||
|
if n.Left.Type == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
switch n.Left.Op {
|
switch n.Left.Op {
|
||||||
case ODOT, ODOTPTR:
|
case ODOT, ODOTPTR:
|
||||||
break
|
break
|
||||||
|
11
test/fixedbugs/issue22351.go
Normal file
11
test/fixedbugs/issue22351.go
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
// 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 main
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
const _ = uint64(unsafe.Offsetof(T{}.F)) // ERROR "undefined"
|
@ -11,7 +11,5 @@ package main
|
|||||||
import "unsafe"
|
import "unsafe"
|
||||||
|
|
||||||
var x struct {
|
var x struct {
|
||||||
a [unsafe.Sizeof(x.a)]int // ERROR "array bound|typechecking loop|invalid expression"
|
a [unsafe.Sizeof(x.a)]int // ERROR "array bound|typechecking loop|invalid expression"
|
||||||
b [unsafe.Offsetof(x.b)]int // ERROR "array bound"
|
|
||||||
c [unsafe.Alignof(x.c)]int // ERROR "array bound|invalid expression"
|
|
||||||
}
|
}
|
||||||
|
15
test/fixedbugs/issue7525d.go
Normal file
15
test/fixedbugs/issue7525d.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
// Issue 7525: self-referential array types.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
var x struct {
|
||||||
|
b [unsafe.Offsetof(x.b)]int // ERROR "array bound|typechecking loop|invalid array"
|
||||||
|
}
|
15
test/fixedbugs/issue7525e.go
Normal file
15
test/fixedbugs/issue7525e.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
// Issue 7525: self-referential array types.
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
|
var x struct {
|
||||||
|
c [unsafe.Alignof(x.c)]int // ERROR "array bound|typechecking loop|invalid array"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user