aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2017-05-02 11:15:41 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2017-08-28 05:30:40 +0000
commit53c8be4a8dadc2d4e664d69732032409a9c344d7 (patch)
tree52cac68d9916c2b3cfb267133385412674e58aa5 /src
parenteb07028289f39b9cd4016081fc05c50507ea3340 (diff)
downloadgo-53c8be4a8dadc2d4e664d69732032409a9c344d7.tar.xz
cmd/compile: use raceX instead of raceXrange for types without subcomponents
Change-Id: I9882488e69565dc9da6814fefbdba3621daf74fe Reviewed-on: https://go-review.googlesource.com/59332 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Dmitry Vyukov <dvyukov@google.com> Reviewed-by: Marvin Stenger <marvin.stenger94@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/compile/internal/gc/racewalk.go7
-rw-r--r--src/cmd/compile/internal/types/type.go17
2 files changed, 23 insertions, 1 deletions
diff --git a/src/cmd/compile/internal/gc/racewalk.go b/src/cmd/compile/internal/gc/racewalk.go
index b1c4f223ab..0740abbbe8 100644
--- a/src/cmd/compile/internal/gc/racewalk.go
+++ b/src/cmd/compile/internal/gc/racewalk.go
@@ -504,13 +504,18 @@ func callinstr(np **Node, init *Nodes, wr int, skip int) bool {
name = "msanwrite"
}
f = mkcall(name, nil, init, uintptraddr(n), nodintconst(w))
- } else if flag_race && (t.IsStruct() || t.IsArray()) {
+ } else if flag_race && t.NumComponents() > 1 {
+ // for composite objects we have to write every address
+ // because a write might happen to any subobject.
+ // composites with only one element don't have subobjects, though.
name := "racereadrange"
if wr != 0 {
name = "racewriterange"
}
f = mkcall(name, nil, init, uintptraddr(n), nodintconst(w))
} else if flag_race {
+ // for non-composite objects we can write just the start
+ // address, as any write must write the first byte.
name := "raceread"
if wr != 0 {
name = "racewrite"
diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go
index 5c44e62585..3e12cc026c 100644
--- a/src/cmd/compile/internal/types/type.go
+++ b/src/cmd/compile/internal/types/type.go
@@ -1317,6 +1317,23 @@ func (t *Type) SetNumElem(n int64) {
at.Bound = n
}
+func (t *Type) NumComponents() int64 {
+ switch t.Etype {
+ case TSTRUCT:
+ if t.IsFuncArgStruct() {
+ Fatalf("NumComponents func arg struct")
+ }
+ var n int64
+ for _, f := range t.FieldSlice() {
+ n += f.Type.NumComponents()
+ }
+ return n
+ case TARRAY:
+ return t.NumElem() * t.Elem().NumComponents()
+ }
+ return 1
+}
+
// ChanDir returns the direction of a channel type t.
// The direction will be one of Crecv, Csend, or Cboth.
func (t *Type) ChanDir() ChanDir {