1
0
mirror of https://github.com/golang/go synced 2024-11-26 05:17:58 -07:00

cmd/cgo/internal/testsanitizers: avoid clang error in msan8.go

In clang 16 the option -fsanitize-memory-param-retval was turned on by
default. That option causes MSAN to issue a warning when calling a
function with an uninitialized value. The msan8 test relies on being
able to do this, in order to get uninitialized values into registers.

This CL fixes the test by adding maybe_undef attributes that tell
clang that it's OK to pass an uninitialized variable. The docs for
maybe_undef say: "Please note that this is an attribute that is used as
an internal implementation detail and not intended to be used by
external users." So this may break in the future, but it does work for now.

Fixes #64616

Change-Id: I0ac8c0520fce8c32e26d2a5efb7ae5e02461c1ce
Reviewed-on: https://go-review.googlesource.com/c/go/+/601779
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Ian Lance Taylor 2024-07-30 11:48:10 -07:00 committed by Gopher Robot
parent 96f7159705
commit 0b7cda77ca

View File

@ -26,12 +26,22 @@ void msanGoTraceback(void* parg) {
arg->buf[0] = 0;
}
// Don't warn if the compiler doesn't support the maybe_undef attribute.
#pragma GCC diagnostic ignored "-Wattributes"
// msanGoWait will be called with all registers undefined as far as
// msan is concerned. It just waits for a signal.
// Because the registers are msan-undefined, the signal handler will
// be invoked with all registers msan-undefined.
// The maybe_undef attribute tells clang to not complain about
// passing uninitialized values.
__attribute__((noinline))
void msanGoWait(unsigned long a1, unsigned long a2, unsigned long a3, unsigned long a4, unsigned long a5, unsigned long a6) {
void msanGoWait(unsigned long a1 __attribute__((maybe_undef)),
unsigned long a2 __attribute__((maybe_undef)),
unsigned long a3 __attribute__((maybe_undef)),
unsigned long a4 __attribute__((maybe_undef)),
unsigned long a5 __attribute__((maybe_undef)),
unsigned long a6 __attribute__((maybe_undef))) {
sigset_t mask;
sigemptyset(&mask);