Skip to content

Commit 2acbdd0

Browse files
mauri870gopherbot
authored andcommitted
cmd/cgo/internal/testsanitizers: fix msan test failing with clang >= 16
Clang 16 introduced a more aggressive behavior regarding uninitialized memory in the memory sanitizer. The new option -fsanitize-memory-param-retval is enabled by default and makes the test msan8 fail, since it uses an uninitialized variable on purpose. Disable this behavior if we are running with clang 16+. Fixes #64616 Change-Id: If366f978bef984ea73f6ae958f24c8fce99b59fe GitHub-Last-Rev: 60bd64a GitHub-Pull-Request: #64691 Reviewed-on: https://go-review.googlesource.com/c/go/+/549297 Auto-Submit: Bryan Mills <[email protected]> Reviewed-by: Bryan Mills <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Than McIntosh <[email protected]>
1 parent a709724 commit 2acbdd0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/cmd/cgo/internal/testsanitizers/msan_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ func TestMSAN(t *testing.T) {
7171
defer dir.RemoveAll(t)
7272

7373
outPath := dir.Join(name)
74-
mustRun(t, config.goCmdWithExperiments("build", []string{"-o", outPath, srcPath(tc.src)}, tc.experiments))
74+
buildcmd := config.goCmdWithExperiments("build", []string{"-o", outPath, srcPath(tc.src)}, tc.experiments)
75+
// allow tests to define -f flags in CGO_CFLAGS
76+
replaceEnv(buildcmd, "CGO_CFLAGS_ALLOW", "-f.*")
77+
mustRun(t, buildcmd)
7578

7679
cmd := hangProneCmd(outPath)
7780
if tc.wantErr {

src/cmd/cgo/internal/testsanitizers/testdata/msan8.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
package main
66

77
/*
8+
// For clang >= 16, uninitialized memory is more aggressively reported.
9+
// Restore the old behavior for this particular test as it relies on
10+
// uninitialized variables. See #64616
11+
#if __clang_major__ >= 16
12+
#cgo CFLAGS: -fno-sanitize-memory-param-retval
13+
#endif
14+
815
#include <pthread.h>
916
#include <signal.h>
1017
#include <stdint.h>

0 commit comments

Comments
 (0)