go/analysis/passes/atomic: add a test that uses typeparams

This atomic check simply inspects whether sync/atomic.Add*
are used and LHS looks identical to the first arg of the call.
In the current implementation, this does not require handling
of type params. This test shows the addition of typeparams
doesn't crash the vet.

Update golang/go#48704

Change-Id: I79f9d782595f6bf2db82237afdbef1ffdf6f808e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/353550
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/go/analysis/passes/atomic/atomic_test.go b/go/analysis/passes/atomic/atomic_test.go
index f5f60a3..c17064c 100644
--- a/go/analysis/passes/atomic/atomic_test.go
+++ b/go/analysis/passes/atomic/atomic_test.go
@@ -9,9 +9,14 @@
 
 	"golang.org/x/tools/go/analysis/analysistest"
 	"golang.org/x/tools/go/analysis/passes/atomic"
+	"golang.org/x/tools/internal/typeparams"
 )
 
 func Test(t *testing.T) {
 	testdata := analysistest.TestData()
-	analysistest.Run(t, testdata, atomic.Analyzer, "a")
+	tests := []string{"a"}
+	if typeparams.Enabled {
+		tests = append(tests, "typeparams")
+	}
+	analysistest.Run(t, testdata, atomic.Analyzer, tests...)
 }
diff --git a/go/analysis/passes/atomic/testdata/src/typeparams/typeparams.go b/go/analysis/passes/atomic/testdata/src/typeparams/typeparams.go
new file mode 100644
index 0000000..52cf468
--- /dev/null
+++ b/go/analysis/passes/atomic/testdata/src/typeparams/typeparams.go
@@ -0,0 +1,37 @@
+// Copyright 2021 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// This file contains tests for the atomic checker.
+
+package a
+
+import (
+	"sync/atomic"
+)
+
+type Subtractable interface {
+	~int64
+}
+
+func Sub[T Subtractable](addr *T, delta T) T {
+	// the followings result in type errors, but doesn't stop this vet check
+	*addr = atomic.AddInt64(addr, -delta)  // want "direct assignment to atomic value"
+	*addr = atomic.AddUintptr(addr, delta) // want "direct assignment to atomic value"
+	atomic.AddInt64()  // vet ignores it
+	return *addr
+}
+
+type _S[T Subtractable] struct {
+	x *T
+}
+
+func (v _S) AddInt64(_ *int64, delta int64) int64 {
+	*v.x = atomic.AddInt64(v.x, delta)  // want "direct assignment to atomic value"
+	return *v.x
+}
+
+func NonAtomicInt64() {
+	var atomic _S[int64]
+	*atomic.x = atomic.AddInt64(atomic.x, 123)  // ok; AddInt64 is not sync/atomic.AddInt64.
+}
\ No newline at end of file