From: Ian Lance Taylor Date: Wed, 26 Feb 2025 05:35:32 +0000 (-0800) Subject: [release-branch.go1.23] runtime/cgo: avoid errors from -Wdeclaration-after-statement X-Git-Tag: go1.23.7~3 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9facf1f2c25dbd3da63c394e9f7f46b56a53f7ae;p=gostls13.git [release-branch.go1.23] runtime/cgo: avoid errors from -Wdeclaration-after-statement It's used by the SWIG CI build, at least, and it's an easy fix. [The change in x_cgo_sys_thread_create is gone, as that function was already compliant in 1.23.] Fixes #71962 For #71961 Change-Id: Id21071a5aef216b35ecf0e9cd3e05d08972d92fe Reviewed-on: https://go-review.googlesource.com/c/go/+/652181 Reviewed-by: Cherry Mui Reviewed-by: Michael Pratt LUCI-TryBot-Result: Go LUCI Auto-Submit: Michael Pratt (cherry picked from commit 76c70282538bf4cccd6f98b5b26df7f5a7f2cebd) Reviewed-on: https://go-review.googlesource.com/c/go/+/652935 Reviewed-by: Michael Knyszek --- diff --git a/src/runtime/cgo/cgo.go b/src/runtime/cgo/cgo.go index 1e3a502918..6b0acf7023 100644 --- a/src/runtime/cgo/cgo.go +++ b/src/runtime/cgo/cgo.go @@ -25,7 +25,8 @@ package cgo // Use -fno-stack-protector to avoid problems locating the // proper support functions. See issues #52919, #54313, #58385. -#cgo CFLAGS: -Wall -Werror -fno-stack-protector +// Use -Wdeclaration-after-statement because some CI builds use it. +#cgo CFLAGS: -Wall -Werror -fno-stack-protector -Wdeclaration-after-statement #cgo solaris CPPFLAGS: -D_POSIX_PTHREAD_SEMANTICS diff --git a/src/runtime/cgo/gcc_libinit.c b/src/runtime/cgo/gcc_libinit.c index 33a9ff93ca..6cceae34c6 100644 --- a/src/runtime/cgo/gcc_libinit.c +++ b/src/runtime/cgo/gcc_libinit.c @@ -48,9 +48,11 @@ x_cgo_sys_thread_create(void* (*func)(void*), void* arg) { uintptr_t _cgo_wait_runtime_init_done(void) { void (*pfn)(struct context_arg*); + int done; + pfn = __atomic_load_n(&cgo_context_function, __ATOMIC_CONSUME); - int done = 2; + done = 2; if (__atomic_load_n(&runtime_init_done, __ATOMIC_CONSUME) != done) { pthread_mutex_lock(&runtime_init_mu); while (__atomic_load_n(&runtime_init_done, __ATOMIC_CONSUME) == 0) { diff --git a/src/runtime/cgo/gcc_libinit_windows.c b/src/runtime/cgo/gcc_libinit_windows.c index 9a8c65ea29..d43d12a24a 100644 --- a/src/runtime/cgo/gcc_libinit_windows.c +++ b/src/runtime/cgo/gcc_libinit_windows.c @@ -69,8 +69,10 @@ x_cgo_sys_thread_create(void (*func)(void*), void* arg) { int _cgo_is_runtime_initialized() { + int status; + EnterCriticalSection(&runtime_init_cs); - int status = runtime_init_done; + status = runtime_init_done; LeaveCriticalSection(&runtime_init_cs); return status; }