]> Cypherpunks repositories - gostls13.git/commit
cmd/cover: fix problem with race mode and inlining
authorThan McIntosh <thanm@google.com>
Fri, 21 Oct 2022 13:18:44 +0000 (09:18 -0400)
committerThan McIntosh <thanm@google.com>
Fri, 21 Oct 2022 19:41:54 +0000 (19:41 +0000)
commit67403a30f61ac6af584796cdfd45c0d86820690c
treec8682048a7a99822423a19b9dd8566113b18f2df
parent99fcacfe9a09c5df0787eda15ace0f473c50363c
cmd/cover: fix problem with race mode and inlining

This patch fixes a problem in which we can get a data race on a
coverage counter function registration sequence. The scenario is that
package P contains a function F that is built with coverage, then F is
inlined into some other package that isn't being instrumented. Within
F's exported function body counter updates were being done with
atomics, but the initial registration sequence was not, which had the
potential to trigger a race. Fix: if race mode is enabled and we're
using atomics for counter increments, also use atomics in the
registration sequence.

Fixes #56370.

Change-Id: If274b61714b90275ff95fc6529239e9264b0ab0c
Reviewed-on: https://go-review.googlesource.com/c/go/+/444617
Reviewed-by: Cherry Mui <cherryyz@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Than McIntosh <thanm@google.com>
src/cmd/cover/cover.go
src/cmd/go/testdata/script/cover_test_race_issue56370.txt [new file with mode: 0644]