1
0
mirror of https://github.com/golang/go synced 2024-11-07 00:46:20 -07:00
go/misc/cgo/test
Matthew Dempsky 7388956b76 cmd/cgo: fix mangling of enum and union types
Consider this test package:

    package p

    // enum E { E0 };
    // union U { long x; };
    // void f(enum E e, union U* up) {}
    import "C"

    func f() {
    	C.f(C.enum_E(C.E0), (*C.union_U)(nil))
    }

In Go 1.14, cgo translated this to (omitting irrelevant details):

    type _Ctype_union_U [8]byte

    func f() {
    	_Cfunc_f(uint32(_Ciconst_E0), (*[8]byte)(nil))
    }

    func _Cfunc_f(p0 uint32, p1 *[8]byte) (r1 _Ctype_void) { ... }

Notably, _Ctype_union_U was declared as a defined type, but uses were
being rewritten into uses of the underlying type, which matched how
_Cfunc_f was declared.

After CL 230037, cgo started consistently rewriting "C.foo" type
expressions as "_Ctype_foo", which caused it to start emitting:

    type _Ctype_enum_E uint32
    type _Ctype_union_U [8]byte

    func f() {
    	_Cfunc_f(_Ctype_enum_E(_Ciconst_E0), (*_Ctype_union_U)(nil))
    }

    // _Cfunc_f unchanged

Of course, this fails to type-check because _Ctype_enum_E and
_Ctype_union_U are defined types.

This CL changes cgo to emit:

    type _Ctype_enum_E = uint32
    type _Ctype_union_U = [8]byte

    // f unchanged since CL 230037
    // _Cfunc_f still unchanged

It would probably be better to fix this in (*typeConv).loadType so
that cgo generated code uses the _Ctype_foo aliases too. But as it
wouldn't have any effect on actual compilation, it's not worth the
risk of touching it at this point in the release cycle.

Updates #39537.
Fixes #40494.

Change-Id: I88269660b40aeda80a9a9433777601a781b48ac0
Reviewed-on: https://go-review.googlesource.com/c/go/+/246057
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-07-31 16:35:33 +00:00
..
testdata cmd/cgo,cmd/fix,misc/cgo: map the EGLConfig C type to uintptr in Go 2020-05-31 09:48:08 +00:00
backdoor.go
buildid_linux.go
callback_c_gc.c
callback_c_gccgo.c
callback_c.c
callback.go cmd/compile: use existing instructions instead of nops for inline marks 2019-03-25 16:49:29 +00:00
cgo_linux_test.go misc/cgo/test: skip Setgid test on Android 2019-04-08 05:56:14 +00:00
cgo_stubs_android_test.go misc/cgo/test: consolidate tests into fewer cgo source files 2019-05-22 12:52:33 +00:00
cgo_test.go cmd/cgo: build unique C type cache keys from parent names 2019-10-05 00:16:04 +00:00
cgo_thread_lock.go
cgo_unix_test.go
cthread_unix.c cmd/dist, misc/cgo: enable tests for aix/ppc64 2019-03-20 14:38:44 +00:00
cthread_windows.c
issue4029.c cmd/cgo: permit missing dynamic symbol section 2018-07-02 17:50:00 +00:00
issue4029.go cmd/cgo: permit missing dynamic symbol section 2018-07-02 17:50:00 +00:00
issue4029w.go cmd/cgo: permit missing dynamic symbol section 2018-07-02 17:50:00 +00:00
issue4273.c
issue4273b.c
issue4339.c
issue4339.h
issue5548_c.c
issue5740a.c
issue5740b.c
issue6833_c.c
issue6907export_c.c
issue6997_linux.c
issue6997_linux.go
issue7234_test.go
issue8148.go
issue8331.h
issue8517_windows.c
issue8517_windows.go
issue8517.go
issue8694.go
issue8811.c
issue18146.go misc/cgo/test: consolidate tests into fewer cgo source files 2019-05-22 12:52:33 +00:00
issue20910.c
issue21897.go misc/cgo/test: re-enable darwin cgo tests in race mode 2020-01-10 10:04:49 +00:00
issue21897b.go misc/cgo/test: re-enable darwin cgo tests in race mode 2020-01-10 10:04:49 +00:00
issue31891.c cmd/cgo: build unique C type cache keys from parent names 2019-10-05 00:16:04 +00:00
overlaydir_test.go misc: remove use of relative directories in overlayDir functions 2019-11-25 16:26:15 +00:00
pkg_test.go all: remove scattered remnants of darwin/arm 2020-04-08 18:35:49 +00:00
setgid_linux.go
sigaltstack.go all: remove scattered remnants of darwin/386 2020-04-08 18:37:38 +00:00
sigprocmask.c misc/cgo/test: add retry loop around pthread_create in TestSigprocmask 2018-06-27 04:33:10 +00:00
sigprocmask.go misc/cgo/test: log error value in testSigprocmask 2018-04-25 20:26:39 +00:00
test_unix.go misc/cgo/test: consolidate tests into fewer cgo source files 2019-05-22 12:52:33 +00:00
test_windows.go misc/cgo/test: consolidate tests into fewer cgo source files 2019-05-22 12:52:33 +00:00
test.go cmd/cgo: fix mangling of enum and union types 2020-07-31 16:35:33 +00:00
testx.go cmd/cgo: use consistent tag for a particular struct 2020-04-14 18:59:37 +00:00