Skip to content

Commit 9edb84e

Browse files
committed
vulncheck: add support for generics
Make ssa instantiate generics. Fixes golang/go#57174 Change-Id: I2d2e28a48e3a64df3d4d415b4629fe3e0a1ba28d Reviewed-on: https://go-review.googlesource.com/c/vuln/+/456436 Reviewed-by: Fnu Harshavardhana <[email protected]> Run-TryBot: Zvonimir Pavlinovic <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Jonathan Amsterdam <[email protected]>
1 parent 7f7812b commit 9edb84e

File tree

2 files changed

+54
-1
lines changed

2 files changed

+54
-1
lines changed

vulncheck/source_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,3 +848,55 @@ func TestRecursion(t *testing.T) {
848848
t.Errorf("want 3 functions (X, y, Vuln) in vulnerability graph; got %v", l)
849849
}
850850
}
851+
852+
func TestIssue57174(t *testing.T) {
853+
e := packagestest.Export(t, packagestest.Modules, []packagestest.Module{
854+
{
855+
Name: "golang.org/entry",
856+
Files: map[string]interface{}{
857+
"x/x.go": `
858+
package x
859+
860+
import "golang.org/bmod/bvuln"
861+
862+
func P(d [][3]int) {
863+
p(d)
864+
}
865+
866+
func p[E interface{ [3]int | [4]int }](d []E) {
867+
c := d[0]
868+
if c[0] > 0 {
869+
bvuln.Vuln()
870+
}
871+
}
872+
`,
873+
},
874+
},
875+
{
876+
Name: "golang.org/[email protected]",
877+
Files: map[string]interface{}{"bvuln/bvuln.go": `
878+
package bvuln
879+
880+
func Vuln() {}
881+
`},
882+
},
883+
})
884+
defer e.Cleanup()
885+
886+
// Load x as entry package.
887+
pkgs, err := test.LoadPackages(e, path.Join(e.Temp(), "entry/x"))
888+
if err != nil {
889+
t.Fatal(err)
890+
}
891+
if len(pkgs) != 1 {
892+
t.Fatal("failed to load x test package")
893+
}
894+
895+
cfg := &Config{
896+
Client: testClient,
897+
}
898+
_, err = Source(context.Background(), Convert(pkgs), cfg)
899+
if err != nil {
900+
t.Fatal(err)
901+
}
902+
}

vulncheck/utils.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import (
2424
// the ssa program encapsulating the packages and top level
2525
// ssa packages corresponding to pkgs.
2626
func buildSSA(pkgs []*Package, fset *token.FileSet) (*ssa.Program, []*ssa.Package) {
27-
prog := ssa.NewProgram(fset, ssa.BuilderMode(0))
27+
// TODO(#57221): what about entry functions that are generics?
28+
prog := ssa.NewProgram(fset, ssa.InstantiateGenerics)
2829

2930
imports := make(map[*Package]*ssa.Package)
3031
var createImports func([]*Package)

0 commit comments

Comments
 (0)