mirror of
https://github.com/golang/go
synced 2024-11-19 13:04:45 -07:00
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>
This commit is contained in:
parent
eb07028289
commit
53c8be4a8d
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user