Commit 2a983aa3 authored by Shenghou Ma's avatar Shenghou Ma

cmd/cgo: silence two gcc warnings for *.cgo2.c

1. "int e;" is unused, generating "unused variable" error.
2. a->e was typed void *[2], but was accessed with *(int *)(a->e), this
generated "dereferencing type-punned pointer will break strict-aliasing rules" error.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/11009043
parent 72faa4bc
...@@ -47,7 +47,7 @@ func (p *Package) writeDefs() { ...@@ -47,7 +47,7 @@ func (p *Package) writeDefs() {
} else { } else {
// If we're not importing runtime/cgo, we *are* runtime/cgo, // If we're not importing runtime/cgo, we *are* runtime/cgo,
// which provides crosscall2. We just need a prototype. // which provides crosscall2. We just need a prototype.
fmt.Fprintf(fm, "void crosscall2(void(*fn)(void*, int), void *a, int c);") fmt.Fprintf(fm, "void crosscall2(void(*fn)(void*, int), void *a, int c);\n")
} }
fmt.Fprintf(fm, "void _cgo_allocate(void *a, int c) { }\n") fmt.Fprintf(fm, "void _cgo_allocate(void *a, int c) { }\n")
fmt.Fprintf(fm, "void _cgo_panic(void *a, int c) { }\n") fmt.Fprintf(fm, "void _cgo_panic(void *a, int c) { }\n")
...@@ -282,7 +282,7 @@ func (p *Package) structType(n *Name) (string, int64) { ...@@ -282,7 +282,7 @@ func (p *Package) structType(n *Name) (string, int64) {
off += pad off += pad
} }
if n.AddError { if n.AddError {
fmt.Fprint(&buf, "\t\tvoid *e[2]; /* error */\n") fmt.Fprint(&buf, "\t\tint e[2*sizeof(void *)/sizeof(int)]; /* error */\n")
off += 2 * p.PtrSize off += 2 * p.PtrSize
} }
if off == 0 { if off == 0 {
...@@ -478,7 +478,6 @@ func (p *Package) writeOutputFunc(fgcc *os.File, n *Name) { ...@@ -478,7 +478,6 @@ func (p *Package) writeOutputFunc(fgcc *os.File, n *Name) {
fmt.Fprintf(fgcc, "_cgo%s%s(void *v)\n", cPrefix, n.Mangle) fmt.Fprintf(fgcc, "_cgo%s%s(void *v)\n", cPrefix, n.Mangle)
fmt.Fprintf(fgcc, "{\n") fmt.Fprintf(fgcc, "{\n")
if n.AddError { if n.AddError {
fmt.Fprintf(fgcc, "\tint e;\n") // assuming 32 bit (see comment above structType)
fmt.Fprintf(fgcc, "\terrno = 0;\n") fmt.Fprintf(fgcc, "\terrno = 0;\n")
} }
// We're trying to write a gcc struct that matches 6c/8c/5c's layout. // We're trying to write a gcc struct that matches 6c/8c/5c's layout.
......
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