]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/cgo: fix unused parameter warnings in generated _cgo_main.c
authorHans <hzb153@gmail.com>
Fri, 30 Jul 2021 02:36:02 +0000 (02:36 +0000)
committerIan Lance Taylor <iant@golang.org>
Mon, 16 Aug 2021 23:03:03 +0000 (23:03 +0000)
Applying -Werror compiler option to request warnings is an usual
way to discover potential errors. Go user may put a cgo directive
in preamble: `// #cgo CFLAGS: -Werror=unused-parameter`.

However, the directive also takes effect on the cgo generated files.
I cleaned _cgo_main.c to help Go user only concentrate on warnings
of their own file.

Fixes #43639

Change-Id: I9112f02ae5226f2fc87a8650d19faee59cddd588
GitHub-Last-Rev: f09d172f979acfba855be8108e7d79ec2778c406
GitHub-Pull-Request: golang/go#46358
Reviewed-on: https://go-review.googlesource.com/c/go/+/322232
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Bryan C. Mills <bcmills@google.com>

misc/cgo/test/testdata/issue43639.go [new file with mode: 0644]
misc/cgo/test/testdata/issue43639/a.go [new file with mode: 0644]
src/cmd/cgo/out.go

diff --git a/misc/cgo/test/testdata/issue43639.go b/misc/cgo/test/testdata/issue43639.go
new file mode 100644 (file)
index 0000000..e755fbd
--- /dev/null
@@ -0,0 +1,9 @@
+// Copyright 2021 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
+
+// Issue 43639: No runtime test needed, make sure package cgotest/issue43639 compiles well.
+
+import _ "cgotest/issue43639"
diff --git a/misc/cgo/test/testdata/issue43639/a.go b/misc/cgo/test/testdata/issue43639/a.go
new file mode 100644 (file)
index 0000000..fe37d5e
--- /dev/null
@@ -0,0 +1,8 @@
+// Copyright 2021 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 issue43639
+
+// #cgo CFLAGS: -W -Wall -Werror
+import "C"
index 94152f4278cb04b44325a936c50d8d11887f4b3d..3badd73f7942288def0364a74b545ec2424ccda9 100644 (file)
@@ -59,9 +59,9 @@ func (p *Package) writeDefs() {
        // Write C main file for using gcc to resolve imports.
        fmt.Fprintf(fm, "int main() { return 0; }\n")
        if *importRuntimeCgo {
-               fmt.Fprintf(fm, "void crosscall2(void(*fn)(void*), void *a, int c, __SIZE_TYPE__ ctxt) { }\n")
+               fmt.Fprintf(fm, "void crosscall2(void(*fn)(void*) __attribute__((unused)), void *a __attribute__((unused)), int c __attribute__((unused)), __SIZE_TYPE__ ctxt __attribute__((unused))) { }\n")
                fmt.Fprintf(fm, "__SIZE_TYPE__ _cgo_wait_runtime_init_done(void) { return 0; }\n")
-               fmt.Fprintf(fm, "void _cgo_release_context(__SIZE_TYPE__ ctxt) { }\n")
+               fmt.Fprintf(fm, "void _cgo_release_context(__SIZE_TYPE__ ctxt __attribute__((unused))) { }\n")
                fmt.Fprintf(fm, "char* _cgo_topofstack(void) { return (char*)0; }\n")
        } else {
                // If we're not importing runtime/cgo, we *are* runtime/cgo,
@@ -70,8 +70,8 @@ func (p *Package) writeDefs() {
                fmt.Fprintf(fm, "__SIZE_TYPE__ _cgo_wait_runtime_init_done(void);\n")
                fmt.Fprintf(fm, "void _cgo_release_context(__SIZE_TYPE__);\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_allocate(void *a __attribute__((unused)), int c __attribute__((unused))) { }\n")
+       fmt.Fprintf(fm, "void _cgo_panic(void *a __attribute__((unused)), int c __attribute__((unused))) { }\n")
        fmt.Fprintf(fm, "void _cgo_reginit(void) { }\n")
 
        // Write second Go output: definitions of _C_xxx.