From 718ddee9569ab27cee4900b77d6f38f1ddbbbf39 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 2 Feb 2019 20:07:21 +0000 Subject: [PATCH] Revert "go/analysis/passes/atomicalign: handle pointers to struct" This reverts CL 158999, commit 8dbcc66f33bb0acac38e8777732a369d38151a35. 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 TryBot-Result: Gobot Gobot Reviewed-by: Alan Donovan --- go/analysis/passes/atomicalign/atomicalign.go | 12 +++++------- .../passes/atomicalign/testdata/src/a/a.go | 19 ------------------- 2 files changed, 5 insertions(+), 26 deletions(-) diff --git a/go/analysis/passes/atomicalign/atomicalign.go b/go/analysis/passes/atomicalign/atomicalign.go index 0326bf536b7..d3fc3e2d731 100644 --- a/go/analysis/passes/atomicalign/atomicalign.go +++ b/go/analysis/passes/atomicalign/atomicalign.go @@ -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, } @@ -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) @@ -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 } diff --git a/go/analysis/passes/atomicalign/testdata/src/a/a.go b/go/analysis/passes/atomicalign/testdata/src/a/a.go index 7aa7278e444..45dd73d3ac5 100644 --- a/go/analysis/passes/atomicalign/testdata/src/a/a.go +++ b/go/analysis/passes/atomicalign/testdata/src/a/a.go @@ -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) -}