Commit fba96e91 authored by Rémy Oudompheng's avatar Rémy Oudompheng

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
parent 77c34332
......@@ -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];
......
// 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))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment