Alan Donovan submitted the change with unreviewed changes![Open in Gerrit]()
Unreviewed changes
3 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:
```
The name of the file: go/analysis/passes/modernize/unsafefuncs.go
Insertions: 4, Deletions: 0.
@@ -147,6 +147,10 @@
// Variant: sum.y operand was converted from another integer type.
// Discard the conversion, as Add is generic over integers.
+ //
+ // e.g. unsafe.Pointer(uintptr(ptr) + uintptr(len(s)))
+ // -------- -
+ // unsafe.Add ( ptr, len(s))
if t, _ := isConversion(curY); t != nil && isInteger(t) {
edits = append(edits, deleteConv(curY)...)
}
```
Change information
Commit message:
go/analysis/passes/modernize: unsafefuncs: ptr+int => unsafe.Add
This CL adds a new modernizer (only to gopls for now) that
replaces unsafe pointer arithmetic by calls to helper functions
such as go1.17's unsafe.Add.
We really need some kind of template matcher like the one
in staticcheck, ideally integrated with cursors.
+ tests, docs.
For golang/go#76648
Change-Id: Ia3e7d603efd8a01e723370b485ab83b6838522b8
Files:
- M go/analysis/passes/modernize/doc.go
- M go/analysis/passes/modernize/modernize.go
- M go/analysis/passes/modernize/modernize_test.go
- A go/analysis/passes/modernize/testdata/src/unsafefuncs/unsafefuncs.go
- A go/analysis/passes/modernize/testdata/src/unsafefuncs/unsafefuncs.go.golden
- A go/analysis/passes/modernize/unsafefuncs.go
- M go/types/typeutil/callee.go
- M gopls/doc/analyzers.md
- M gopls/internal/doc/api.json
- M gopls/internal/settings/analysis.go
- M internal/goplsexport/export.go
- M internal/versions/features.go
Change size: L
Delta: 12 files changed, 319 insertions(+), 0 deletions(-)
Branch: refs/heads/master
Submit Requirements:
Code-Review: +1 by Daniel Morsing, +2 by Madeline Kalil
TryBots-Pass: LUCI-TryBot-Result+1 by Go LUCI
Open in Gerrit
Gerrit-MessageType: merged
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: Ia3e7d603efd8a01e723370b485ab83b6838522b8
Gerrit-Change-Number: 725680
Gerrit-PatchSet: 5