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

gccgo: cannot convert user-defined type whose underlying type is uintptr to unsafe.Pointer #10284

Closed
h4ck3rm1k3 opened this issue Mar 29, 2015 · 5 comments

Comments

@h4ck3rm1k3
Copy link

This example from the go core runtime , trying to compile with

unsafe_pointer.go:13:21: error: invalid type conversion (cannot use type gclinkptr as type unsafe.Pointer)
  x := unsafe.Pointer(v)
package main
import  "unsafe"
import  "fmt"
type gclinkptr uintptr
type mspan struct {
        freelist gclinkptr // list of free objects                                                                                                                
}

func main() {
    var a mspan 
    var s *mspan
    s = &a
        v := s.freelist
        x := unsafe.Pointer(v)
    fmt.Println(x)
}

See code here on play :
http://play.golang.org/p/HkMAa-VU0x

@bradfitz
Copy link
Contributor

/cc @ianlancetaylor for gccgo

@h4ck3rm1k3
Copy link
Author

see a mention of something similar conformal/gotk3#58 (comment)

@h4ck3rm1k3
Copy link
Author

strange, this works
it looks like the type is not begin resolved.

package main
import"unsafe"
import"fmt"
type mspan struct {
        freelist uintptr // list of free objects                                                                                                                  
}
func main() {
        var a mspan
        var s *mspan
        s = &a
        v := s.freelist
        x := unsafe.Pointer(v)
        fmt.Println(x)
}

@minux
Copy link
Member

minux commented Mar 30, 2015 via email

@minux minux changed the title gccgo cannot use type uintptr as type unsafe.Pointer gccgo: cannot convert user-defined type whose underlying type is uintptr to unsafe.Pointer Mar 30, 2015
@ianlancetaylor
Copy link
Contributor

Fixed on tip.

marxin pushed a commit to marxin/gccold that referenced this issue Mar 30, 2015
Any type whose underlying type is uintptr can be converted
to unsafe.Pointer, and vice versa.

Fixes golang/go#10284.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@221774 138bc75d-0d04-0410-961f-82ee72b054a4
ianlancetaylor pushed a commit to golang/gofrontend that referenced this issue Jun 2, 2015
Any type whose underlying type is uintptr can be converted
to unsafe.Pointer, and vice versa.

Fixes golang/go#10284.

LGTM=iant
R=iant
CC=gofrontend-dev
https://golang.org/cl/220480043
@golang golang locked and limited conversation to collaborators Jun 25, 2016
asiekierka pushed a commit to WonderfulToolchain/gcc-ia16 that referenced this issue May 16, 2022
Any type whose underlying type is uintptr can be converted
to unsafe.Pointer, and vice versa.

Fixes golang/go#10284.

From-SVN: r221774
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants