]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: disable GCC 9 warnings triggered by cgo code
authorIan Lance Taylor <iant@golang.org>
Mon, 28 Jan 2019 20:31:55 +0000 (12:31 -0800)
committerIan Lance Taylor <iant@golang.org>
Wed, 30 Jan 2019 22:25:36 +0000 (22:25 +0000)
GCC 9 has started emitting warnings when taking the address of a field
in a packed struct may cause a misaligned pointer. We use packed
structs in cgo to ensure that our field layout matches the C
compiler's layout. Our pointers are always aligned, so disable the warning

Fixes #29962

Change-Id: I7e290a7cf694a2c2958529e340ebed9fcd62089c
Reviewed-on: https://go-review.googlesource.com/c/159859
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/cgo/out.go

index 00e2f9769cd93b3938360f4948d06ade91c26f25..1a6f17cedd54e5e55b2b058d360a31c17bd74dd1 100644 (file)
@@ -776,6 +776,10 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) {
        fmt.Fprintf(fgcc, "#include <stdlib.h>\n")
        fmt.Fprintf(fgcc, "#include \"_cgo_export.h\"\n\n")
 
+       // We use packed structs, but they are always aligned.
+       fmt.Fprintf(fgcc, "#pragma GCC diagnostic ignored \"-Wpragmas\"\n")
+       fmt.Fprintf(fgcc, "#pragma GCC diagnostic ignored \"-Waddress-of-packed-member\"\n")
+
        fmt.Fprintf(fgcc, "extern void crosscall2(void (*fn)(void *, int, __SIZE_TYPE__), void *, int, __SIZE_TYPE__);\n")
        fmt.Fprintf(fgcc, "extern __SIZE_TYPE__ _cgo_wait_runtime_init_done();\n")
        fmt.Fprintf(fgcc, "extern void _cgo_release_context(__SIZE_TYPE__);\n\n")
@@ -1473,6 +1477,10 @@ __cgo_size_assert(double, 8)
 
 extern char* _cgo_topofstack(void);
 
+/* We use packed structs, but they are always aligned.  */
+#pragma GCC diagnostic ignored "-Wpragmas"
+#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
+
 #include <errno.h>
 #include <string.h>
 `