Skip to content

Commit

Permalink
Revert "go/analysis/passes/atomicalign: handle pointers to struct"
Browse files Browse the repository at this point in the history
This reverts CL 158999, commit 8dbcc66.

Reason for revert: broke the build, nobody ever ran trybots

Change-Id: I2180ed8f9281b413b2ffea086abbd09fbfc3c99e
Reviewed-on: https://go-review.googlesource.com/c/160839
Run-TryBot: Brad Fitzpatrick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Alan Donovan <[email protected]>
  • Loading branch information
bradfitz authored and adonovan committed Feb 2, 2019
1 parent 51e363b commit 718ddee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
12 changes: 5 additions & 7 deletions go/analysis/passes/atomicalign/atomicalign.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

var Analyzer = &analysis.Analyzer{
Name: "atomicalign",
Doc: "check for non-64-bit-aligned arguments to sync/atomic functions",
Doc: "check for non-64-bits-aligned arguments to sync/atomic functions",
Requires: []*analysis.Analyzer{inspect.Analyzer},
Run: run,
}
Expand Down Expand Up @@ -70,7 +70,7 @@ func run(pass *analysis.Pass) (interface{}, error) {
}

func check64BitAlignment(pass *analysis.Pass, funcName string, arg ast.Expr) {
// Checks the argument is made of the address operator (&) applied
// Checks the argument is made of the address operator (&) applied to
// to a struct field (as opposed to a variable as the first word of
// uint64 and int64 variables can be relied upon to be 64-bit aligned.
unary, ok := arg.(*ast.UnaryExpr)
Expand All @@ -80,18 +80,16 @@ func check64BitAlignment(pass *analysis.Pass, funcName string, arg ast.Expr) {

// Retrieve the types.Struct in order to get the offset of the
// atomically accessed field.
selector, ok := unary.X.(*ast.SelectorExpr)
sel, ok := unary.X.(*ast.SelectorExpr)
if !ok {
return
}

sel := pass.TypesInfo.Selections[selector]
tvar, ok := sel.Obj().(*types.Var)
tvar, ok := pass.TypesInfo.Selections[sel].Obj().(*types.Var)
if !ok || !tvar.IsField() {
return
}

stype, ok := sel.Recv().Underlying().(*types.Struct)
stype, ok := pass.TypesInfo.Types[sel.X].Type.Underlying().(*types.Struct)
if !ok {
return
}
Expand Down
19 changes: 0 additions & 19 deletions go/analysis/passes/atomicalign/testdata/src/a/a.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,22 +228,3 @@ func embeddedStructFields() {
atomic.AddUint64(&s1.b, 9) // want "address of non 64-bit aligned field .b passed to atomic.AddUint64"
atomic.AddInt64(&s1.c, 9)
}

type t struct {
_ int32
a int64
_ int16
_ int16
b uint64
}

func (t *t) structPointerReceiver() {
atomic.LoadInt64(&t.a) // want "address of non 64-bit aligned field .a passed to atomic.LoadInt64"
atomic.LoadUint64(&t.b)
}

func structPointer() {
t := &t{}
atomic.StoreInt64(&t.a, -1) // want "address of non 64-bit aligned field .a passed to atomic.StoreInt64"
atomic.StoreUint64(&t.b, 1)
}

0 comments on commit 718ddee

Please sign in to comment.