Skip to content

Commit 45a5271

Browse files
ianlancetaylorgopherbot
authored andcommitted
[release-branch.go1.24] runtime/cgo: avoid errors from -Wdeclaration-after-statement
It's used by the SWIG CI build, at least, and it's an easy fix. Fixes #71963 For #71961 Change-Id: Id21071a5aef216b35ecf0e9cd3e05d08972d92fe Reviewed-on: https://go-review.googlesource.com/c/go/+/652181 Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Michael Pratt <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Michael Pratt <[email protected]> (cherry picked from commit 76c7028) Reviewed-on: https://go-review.googlesource.com/c/go/+/652936 Reviewed-by: Michael Knyszek <[email protected]>
1 parent 7f375e2 commit 45a5271

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

src/runtime/cgo/cgo.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ package cgo
2525
2626
// Use -fno-stack-protector to avoid problems locating the
2727
// proper support functions. See issues #52919, #54313, #58385.
28-
#cgo CFLAGS: -Wall -Werror -fno-stack-protector
28+
// Use -Wdeclaration-after-statement because some CI builds use it.
29+
#cgo CFLAGS: -Wall -Werror -fno-stack-protector -Wdeclaration-after-statement
2930
3031
#cgo solaris CPPFLAGS: -D_POSIX_PTHREAD_SEMANTICS
3132

src/runtime/cgo/gcc_libinit.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ void
3939
x_cgo_sys_thread_create(void* (*func)(void*), void* arg) {
4040
pthread_attr_t attr;
4141
pthread_t p;
42+
int err;
4243

4344
pthread_attr_init(&attr);
4445
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
45-
int err = _cgo_try_pthread_create(&p, &attr, func, arg);
46+
err = _cgo_try_pthread_create(&p, &attr, func, arg);
4647
if (err != 0) {
4748
fprintf(stderr, "pthread_create failed: %s", strerror(err));
4849
abort();
@@ -52,9 +53,11 @@ x_cgo_sys_thread_create(void* (*func)(void*), void* arg) {
5253
uintptr_t
5354
_cgo_wait_runtime_init_done(void) {
5455
void (*pfn)(struct context_arg*);
56+
int done;
57+
5558
pfn = __atomic_load_n(&cgo_context_function, __ATOMIC_CONSUME);
5659

57-
int done = 2;
60+
done = 2;
5861
if (__atomic_load_n(&runtime_init_done, __ATOMIC_CONSUME) != done) {
5962
pthread_mutex_lock(&runtime_init_mu);
6063
while (__atomic_load_n(&runtime_init_done, __ATOMIC_CONSUME) == 0) {

src/runtime/cgo/gcc_libinit_windows.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ x_cgo_sys_thread_create(void (*func)(void*), void* arg) {
7575

7676
int
7777
_cgo_is_runtime_initialized() {
78+
int status;
79+
7880
EnterCriticalSection(&runtime_init_cs);
79-
int status = runtime_init_done;
81+
status = runtime_init_done;
8082
LeaveCriticalSection(&runtime_init_cs);
8183
return status;
8284
}

0 commit comments

Comments
 (0)