Skip to content

Commit

Permalink
Update dot_test.go
Browse files Browse the repository at this point in the history
  • Loading branch information
picatz committed Jan 6, 2024
1 parent fa43fa6 commit f437dfe
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions callgraphutil/dot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,33 @@ func loadSSA(ctx context.Context, pkgs []*packages.Package) (mainFn *ssa.Functio
// Analyze the package.
ssaProg, ssaPkgs := ssautil.Packages(pkgs, ssaBuildMode)

// It's possible that the ssaProg is nil?
if ssaProg == nil {
err = fmt.Errorf("failed to create new ssa program")
return
}

ssaProg.Build()

for _, pkg := range ssaPkgs {
if pkg == nil {
continue
}
pkg.Build()
}

// Remove nil ssaPkgs by iterating over the slice of packages
// and for each nil package, we append the slice up to that
// index and then append the slice from the next index to the
// end of the slice. This effectively removes the nil package
// from the slice without having to allocate a new slice.
for i := 0; i < len(ssaPkgs); i++ {
if ssaPkgs[i] == nil {
ssaPkgs = append(ssaPkgs[:i], ssaPkgs[i+1:]...)
i--
}
}

mainPkgs := ssautil.MainPackages(ssaPkgs)

mainFn = mainPkgs[0].Members["main"].(*ssa.Function)
Expand Down

0 comments on commit f437dfe

Please sign in to comment.