aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorAustin Clements <austin@google.com>2020-11-11 15:33:39 -0500
committerAustin Clements <austin@google.com>2020-11-13 15:15:15 +0000
commitf423d616b15302730c1b737a3b22afca315a7fbe (patch)
tree3b920dec7950a8e483710eeed9b84d06bcb125a1 /misc
parent35455fff0ebb7dd1b8e698f245a823ef8c711ac9 (diff)
downloadgo-f423d616b15302730c1b737a3b22afca315a7fbe.tar.gz
go-f423d616b15302730c1b737a3b22afca315a7fbe.zip
cmd/cgo: fix initialization of empty argument types
CL 258938 changed the way C to Go calls work such that they now construct a C struct on the C side for the arguments and space for the results. Any pointers in the result space must be zeroed, so we just zero the whole struct. However, C makes it surprisingly hard to robustly zero any struct type. We had used a "{0}" initializer, which works in the vast majority of cases, but fails if the type is empty or effectively empty. This CL fixes this by changing how the cgo tool zero-initializes the argument struct to be more robust. Fixes #42495. Change-Id: Id1749b9d751e59eb7a02a9d44fec0698a2bf63cd Reviewed-on: https://go-review.googlesource.com/c/go/+/269337 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'misc')
-rw-r--r--misc/cgo/test/issue42495.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/misc/cgo/test/issue42495.go b/misc/cgo/test/issue42495.go
new file mode 100644
index 0000000000..509a67d9a3
--- /dev/null
+++ b/misc/cgo/test/issue42495.go
@@ -0,0 +1,15 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package cgotest
+
+// typedef struct { } T42495A;
+// typedef struct { int x[0]; } T42495B;
+import "C"
+
+//export Issue42495A
+func Issue42495A(C.T42495A) {}
+
+//export Issue42495B
+func Issue42495B(C.T42495B) {}