mirror of
https://github.com/golang/go
synced 2024-11-26 02:07:57 -07:00
cmd/gc: fix uintptr(nil) issues.
A constant node of type uintptr with a nil literal could happen in two cases: []int(nil)[1:] and uintptr(unsafe.Pointer(nil)). Fixes #4614. R=golang-dev, rsc CC=golang-dev https://golang.org/cl/7059043
This commit is contained in:
parent
77c343328e
commit
fba96e915d
@ -162,6 +162,16 @@ convlit1(Node **np, Type *t, int explicit)
|
||||
case TFUNC:
|
||||
case TUNSAFEPTR:
|
||||
break;
|
||||
|
||||
case TUINTPTR:
|
||||
// A nil literal may be converted to uintptr
|
||||
// if it is an unsafe.Pointer
|
||||
if(n->type->etype == TUNSAFEPTR) {
|
||||
n->val.u.xval = mal(sizeof(*n->val.u.xval));
|
||||
mpmovecfix(n->val.u.xval, 0);
|
||||
n->val.ctype = CTINT;
|
||||
} else
|
||||
goto bad;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -810,7 +810,11 @@ cgen_slice(Node *n, Node *res)
|
||||
checkref(n->left);
|
||||
}
|
||||
|
||||
src = *n->left;
|
||||
if(isnil(n->left)) {
|
||||
tempname(&src, n->left->type);
|
||||
cgen(n->left, &src);
|
||||
} else
|
||||
src = *n->left;
|
||||
src.xoffset += Array_array;
|
||||
src.type = types[TUINTPTR];
|
||||
|
||||
|
20
test/fixedbugs/issue4614.go
Normal file
20
test/fixedbugs/issue4614.go
Normal file
@ -0,0 +1,20 @@
|
||||
// compile
|
||||
|
||||
// Copyright 2012 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 4614: slicing of nil slices confuses the compiler
|
||||
// with a uintptr(nil) node.
|
||||
|
||||
package p
|
||||
|
||||
import "unsafe"
|
||||
|
||||
var n int
|
||||
|
||||
var _ = []int(nil)[1:]
|
||||
var _ = []int(nil)[n:]
|
||||
|
||||
var _ = uintptr(unsafe.Pointer(nil))
|
||||
var _ = unsafe.Pointer(uintptr(0))
|
Loading…
Reference in New Issue
Block a user