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 <hrshvardhana@gmail.com>
Run-TryBot: Zvonimir Pavlinovic <zpavlinovic@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Jonathan Amsterdam <jba@google.com>
diff --git a/vulncheck/source_test.go b/vulncheck/source_test.go
index 578d611..006c549 100644
--- a/vulncheck/source_test.go
+++ b/vulncheck/source_test.go
@@ -848,3 +848,55 @@
t.Errorf("want 3 functions (X, y, Vuln) in vulnerability graph; got %v", l)
}
}
+
+func TestIssue57174(t *testing.T) {
+ e := packagestest.Export(t, packagestest.Modules, []packagestest.Module{
+ {
+ Name: "golang.org/entry",
+ Files: map[string]interface{}{
+ "x/x.go": `
+ package x
+
+ import "golang.org/bmod/bvuln"
+
+ func P(d [][3]int) {
+ p(d)
+ }
+
+ func p[E interface{ [3]int | [4]int }](d []E) {
+ c := d[0]
+ if c[0] > 0 {
+ bvuln.Vuln()
+ }
+ }
+ `,
+ },
+ },
+ {
+ Name: "golang.org/bmod@v0.5.0",
+ Files: map[string]interface{}{"bvuln/bvuln.go": `
+ package bvuln
+
+ func Vuln() {}
+ `},
+ },
+ })
+ defer e.Cleanup()
+
+ // Load x as entry package.
+ pkgs, err := test.LoadPackages(e, path.Join(e.Temp(), "entry/x"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ if len(pkgs) != 1 {
+ t.Fatal("failed to load x test package")
+ }
+
+ cfg := &Config{
+ Client: testClient,
+ }
+ _, err = Source(context.Background(), Convert(pkgs), cfg)
+ if err != nil {
+ t.Fatal(err)
+ }
+}
diff --git a/vulncheck/utils.go b/vulncheck/utils.go
index 878b76c..29effbe 100644
--- a/vulncheck/utils.go
+++ b/vulncheck/utils.go
@@ -24,7 +24,8 @@
// the ssa program encapsulating the packages and top level
// ssa packages corresponding to pkgs.
func buildSSA(pkgs []*Package, fset *token.FileSet) (*ssa.Program, []*ssa.Package) {
- prog := ssa.NewProgram(fset, ssa.BuilderMode(0))
+ // TODO(#57221): what about entry functions that are generics?
+ prog := ssa.NewProgram(fset, ssa.InstantiateGenerics)
imports := make(map[*Package]*ssa.Package)
var createImports func([]*Package)