Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: cannot convert uint to uintptr #13263

Closed
dvyukov opened this issue Nov 16, 2015 · 9 comments
Closed

cmd/compile: cannot convert uint to uintptr #13263

dvyukov opened this issue Nov 16, 2015 · 9 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Nov 16, 2015

cmd/compile fails on the following correct program:

package b

var (
    w []*uint
    x = *w[0]
    y = x
    z = (uintptr)(y)
)
./go.go:7: cannot use x (type uint) as type uintptr in assignment

gotype eats it.

go version devel +25a28da Sun Nov 15 23:41:28 2015 +0000 linux/amd64

Found with GoSmith (https://github.com/dvyukov/gosmith).

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Nov 16, 2015
@griesemer
Copy link
Contributor

This is unrelated to the new parser; the same error appears with the old parser:
go tool compile -oldparser foo.go

@mdempsky
Copy link
Member

Slightly simpler repro:

package b

var (
    x uint
    y = x
    z = uintptr(y)
)

The problem is when staticassign is looking at the "z = uintptr(y)" node, it strips the OCONVNOP, finds the ONAME node for y, and then calls staticcopy(z, y, out).

staticcopy(z, y, out) reaches the case ONAME, recursively calls staticcopy(z, x, out) which returns false (because x's Defn is nil), and then synthesizes a "z = x" assignment, which later fails typechecking.

One fix seems to be to reinsert OCONVNOP nodes as necessary when generating that OAS node.

@rsc rsc modified the milestones: Go1.7, Go1.6 Dec 5, 2015
@rsc rsc modified the milestones: Go1.8, Go1.7 May 17, 2016
@odeke-em
Copy link
Member

This bug no longer seems to be an issue on Go1.6.2 at least. See https://play.golang.org/p/4GCc3_5qoT
screen shot 2016-08-11 at 9 27 55 pm

or inlined

package main

import (
    "fmt"
    "runtime"
)

func f1() {
    var (
        w []*uint
        x = *w[0]
        y = x
        z = (uintptr)(y)
    )
    fmt.Printf("z: %v\n", z)
}

func f2() {
    var (
        x uint
        y = x
        z = uintptr(y)
    )
    fmt.Printf("z: %v\n", z)
}

func main() {
    fmt.Printf("Version: %s\n", runtime.Version())
}

screen shot 2016-08-11 at 9 27 02 pm

@griesemer
Copy link
Contributor

Still an issue with 1.7.

@quentinmit quentinmit added the NeedsFix The path to resolution is known, but the work has not been done. label Oct 11, 2016
@rsc rsc modified the milestones: Go1.9, Go1.8 Oct 21, 2016
@odeke-em
Copy link
Member

@griesemer I am running Version: devel +7e45516 Sat Nov 26 05:01:32 2016 +0000 and the test program in #13263 (comment) compiles alright. Would you mind double checking?

@odeke-em
Copy link
Member

Actually you are right(I stand corrected): with @dvyukov's test program with the global declarations it fails to compile but when I put them in functions, it compiles correctly.

@gopherbot
Copy link

CL https://golang.org/cl/33900 mentions this issue.

@odeke-em
Copy link
Member

odeke-em commented Dec 5, 2016

Reported offline by @cherrymui in my CL https://golang.org/cl/33900, the problem seems broader
and not only from uint to uintptr in global declarations, but also in uint to uint64.

package a

var (
	a uint
	b = a
	c = (uint64)(b)
)

@gopherbot
Copy link

CL https://golang.org/cl/33970 mentions this issue.

@golang golang locked and limited conversation to collaborators Dec 6, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

8 participants