Commit 53c8be4a authored by Josh Bleecher Snyder's avatar Josh Bleecher Snyder

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: default avatarDmitry Vyukov <dvyukov@google.com>
Reviewed-by: default avatarMarvin Stenger <marvin.stenger94@gmail.com>
parent eb070282
......@@ -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"
......
......@@ -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 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment