Skip to content

Commit f2a416b

Browse files
cmd/cgo: disable GCC 9 warnings triggered by cgo code
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 7376952 commit f2a416b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/cmd/cgo/out.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,10 @@ func (p *Package) writeExports(fgo2, fm, fgcc, fgcch io.Writer) {
776776
fmt.Fprintf(fgcc, "#include <stdlib.h>\n")
777777
fmt.Fprintf(fgcc, "#include \"_cgo_export.h\"\n\n")
778778

779+
// We use packed structs, but they are always aligned.
780+
fmt.Fprintf(fgcc, "#pragma GCC diagnostic ignored \"-Wpragmas\"\n")
781+
fmt.Fprintf(fgcc, "#pragma GCC diagnostic ignored \"-Waddress-of-packed-member\"\n")
782+
779783
fmt.Fprintf(fgcc, "extern void crosscall2(void (*fn)(void *, int, __SIZE_TYPE__), void *, int, __SIZE_TYPE__);\n")
780784
fmt.Fprintf(fgcc, "extern __SIZE_TYPE__ _cgo_wait_runtime_init_done();\n")
781785
fmt.Fprintf(fgcc, "extern void _cgo_release_context(__SIZE_TYPE__);\n\n")
@@ -1473,6 +1477,10 @@ __cgo_size_assert(double, 8)
14731477
14741478
extern char* _cgo_topofstack(void);
14751479
1480+
/* We use packed structs, but they are always aligned. */
1481+
#pragma GCC diagnostic ignored "-Wpragmas"
1482+
#pragma GCC diagnostic ignored "-Waddress-of-packed-member"
1483+
14761484
#include <errno.h>
14771485
#include <string.h>
14781486
`

0 commit comments

Comments
 (0)