cmd/vet: detect misuse of atomic.Add*
Re-assigning the return value of an atomic operation to the same variable being operated is a common mistake:
x = atomic.AddUint64(&x, 1)
Add this check to go vet.
Fixes issue 4065.
On 2013/01/12 11:24:40, divoxx wrote: > Hello mailto:dvyukov@google.com (cc: mailto:golang-dev@googlegroups.com), > > I'd like you ...
12 years, 2 months ago
(2013-01-12 11:28:08 UTC)
#3
On 2013/01/12 11:24:40, divoxx wrote:
> Hello mailto:dvyukov@google.com (cc: mailto:golang-dev@googlegroups.com),
>
> I'd like you to review this change to
> https://code.google.com/p/go/
I am not a good reviewer for this code. I never worked with AST.
https://codereview.appspot.com/7097048/diff/6001/src/cmd/vet/atomic.go File src/cmd/vet/atomic.go (right): https://codereview.appspot.com/7097048/diff/6001/src/cmd/vet/atomic.go#newcode20 src/cmd/vet/atomic.go:20: if call, ok := rexp.(*ast.CallExpr); ok { the indentation ...
12 years, 2 months ago
(2013-01-12 11:34:24 UTC)
#4
https://codereview.appspot.com/7097048/diff/9002/src/cmd/vet/atomic.go File src/cmd/vet/atomic.go (right): https://codereview.appspot.com/7097048/diff/9002/src/cmd/vet/atomic.go#newcode1 src/cmd/vet/atomic.go:1: // Copyright 2012 The Go Authors. All rights reserved. ...
12 years, 2 months ago
(2013-01-12 23:48:01 UTC)
#8
12 years, 2 months ago
(2013-01-13 02:36:37 UTC)
#11
On 2013/01/13 02:31:02, divoxx wrote:
> Hello mailto:dvyukov@google.com, mailto:golang-dev@googlegroups.com,
mailto:remyoudompheng@gmail.com
> (cc: mailto:golang-dev@googlegroups.com),
>
> Please take another look.
The latest patch include support for checking of structs, pointer to structs,
slices/arrays and slice/arrays of pointers.
It has been refactored to be more readable and easier to understand. New test
cases included.
No, the problem is that your code panicked on my examples because you hadn't addressed ...
12 years, 2 months ago
(2013-01-13 05:42:27 UTC)
#12
No, the problem is that your code panicked on my examples because you
hadn't addressed all comments.
My examples were not supposed to raise any warning, they look like proper
usage.
On 13 Jan 2013 00:51, <divoxx@gmail.com> wrote:
> On 2013/01/12 23:48:01, remyoudompheng wrote:
>
>> https://codereview.appspot.**com/7097048/diff/9002/src/cmd/**
>>
vet/atomic.go<https://codereview.appspot.com/7097048/diff/9002/src/cmd/vet/atomic.go>
>> File src/cmd/vet/atomic.go (right):
>>
>
>
> https://codereview.appspot.**com/7097048/diff/9002/src/cmd/**
>
vet/atomic.go#newcode1<https://codereview.appspot.com/7097048/diff/9002/src/cmd/vet/atomic.go#newcode1>
>
>> src/cmd/vet/atomic.go:1: // Copyright 2012 The Go Authors. All rights
>>
> reserved.
>
>> we are now in 2013
>>
>
>
> https://codereview.appspot.**com/7097048/diff/9002/src/cmd/**
>
vet/atomic.go#newcode80<https://codereview.appspot.com/7097048/diff/9002/src/cmd/vet/atomic.go#newcode80>
>
>> src/cmd/vet/atomic.go:80: }
>> can you check your code works properly on:
>>
>
> var s struct { Counter uint64 }
>> z := atomic.AddUint64(&s.Counter, 1)
>> p := &s.Counter
>> var u [2]uint64
>> u[0] = atomic.AddUint64(p, 1)
>>
>
> thanks.
>>
>
> Unless I'm missing something the code you posted should be fine,
> shouldn't it? You asking to make sure vet does not show the warning/err
> for this?
>
>
https://codereview.appspot.**com/7097048/<https://codereview.appspot.com/7097...
>
12 years, 1 month ago
(2013-01-18 20:36:51 UTC)
#14
Add this:
func (f *File) gofmt(x ast.Expr) string {
f.buf.Reset()
printer.Fprint(&f.b, f.fset, x)
return f.String()
}
Then you can use it in the error message and the tester. Once you have
lhs = atomic.AddXXX(&arg)
you can check if f.gofmt(lhs) == f.gofmt(arg).
Russ, I changed the implementation to do as you suggested. Let me know if that ...
12 years, 1 month ago
(2013-01-21 16:44:15 UTC)
#16
Russ,
I changed the implementation to do as you suggested. Let me know if that is what
you meant.
Cheers
On Jan 18, 2013, at 12:36 PM, rsc@golang.org wrote:
> Add this:
>
> func (f *File) gofmt(x ast.Expr) string {
> f.buf.Reset()
> printer.Fprint(&f.b, f.fset, x)
> return f.String()
> }
>
> Then you can use it in the error message and the tester. Once you have
>
> lhs = atomic.AddXXX(&arg)
>
> you can check if f.gofmt(lhs) == f.gofmt(arg).
>
> https://codereview.appspot.com/7097048/
*** Submitted as https://code.google.com/p/go/source/detail?r=c8cd1f608cd2 *** cmd/vet: detect misuse of atomic.Add* Re-assigning the return value of ...
12 years, 1 month ago
(2013-01-30 15:57:15 UTC)
#20
Issue 7097048: code review 7097048: cmd/vet: detect misuse of atomic.Add*
(Closed)
Created 12 years, 2 months ago by divoxx
Modified 12 years ago
Reviewers:
Base URL:
Comments: 12