]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: use raceX instead of raceXrange for types without subcomponents
authorJosh Bleecher Snyder <josharian@gmail.com>
Tue, 2 May 2017 18:15:41 +0000 (11:15 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Mon, 28 Aug 2017 05:30:40 +0000 (05:30 +0000)
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>
src/cmd/compile/internal/gc/racewalk.go
src/cmd/compile/internal/types/type.go

index b1c4f223abefe9c166d706253ca2f9cfd5e43251..0740abbbe83bf2fa590528116eaafb0e64a0d6dc 100644 (file)
@@ -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"
index 5c44e625856e2dcd78a8895302eeaabf6c088ed5..3e12cc026c53dc808f42396a36b884135907d55b 100644 (file)
@@ -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 {