-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
go/callgraph/rta: add rta analysis test case for multiple go packages
* use go/packages to load packages Change-Id: I6e9f81b282cddc186b4905a23ff635cd98245ac8 GitHub-Last-Rev: a859e27 GitHub-Pull-Request: #513 Reviewed-on: https://go-review.googlesource.com/c/tools/+/609576 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Tim King <taking@google.com> Reviewed-by: Alan Donovan <adonovan@google.com>
- Loading branch information
1 parent
dc4d64c
commit 4fb36d1
Showing
7 changed files
with
216 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
go/callgraph/rta/testdata/iface.go → go/callgraph/rta/testdata/iface.txtar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
-- go.mod -- | ||
module example.com | ||
go 1.18 | ||
|
||
-- iface.go -- | ||
package main | ||
|
||
import ( | ||
"example.com/subpkg" | ||
) | ||
|
||
func use(interface{}) | ||
|
||
// Test of interface calls. | ||
|
||
func main() { | ||
use(subpkg.A(0)) | ||
use(new(subpkg.B)) | ||
use(subpkg.B2(0)) | ||
|
||
var i interface { | ||
F() | ||
} | ||
|
||
// assign an interface type with a function return interface value | ||
i = subpkg.NewInterfaceF() | ||
|
||
i.F() | ||
} | ||
|
||
func dead() { | ||
use(subpkg.D(0)) | ||
} | ||
|
||
// WANT: | ||
// | ||
// edge (*example.com/subpkg.A).F --static method call--> (example.com/subpkg.A).F | ||
// edge (*example.com/subpkg.B2).F --static method call--> (example.com/subpkg.B2).F | ||
// edge (*example.com/subpkg.C).F --static method call--> (example.com/subpkg.C).F | ||
// edge init --static function call--> example.com/subpkg.init | ||
// edge main --dynamic method call--> (*example.com/subpkg.A).F | ||
// edge main --dynamic method call--> (*example.com/subpkg.B).F | ||
// edge main --dynamic method call--> (*example.com/subpkg.B2).F | ||
// edge main --dynamic method call--> (*example.com/subpkg.C).F | ||
// edge main --dynamic method call--> (example.com/subpkg.A).F | ||
// edge main --dynamic method call--> (example.com/subpkg.B2).F | ||
// edge main --dynamic method call--> (example.com/subpkg.C).F | ||
// edge main --static function call--> example.com/subpkg.NewInterfaceF | ||
// edge main --static function call--> use | ||
// | ||
// reachable (*example.com/subpkg.A).F | ||
// reachable (*example.com/subpkg.B).F | ||
// reachable (*example.com/subpkg.B2).F | ||
// reachable (*example.com/subpkg.C).F | ||
// reachable (example.com/subpkg.A).F | ||
// !reachable (example.com/subpkg.B).F | ||
// reachable (example.com/subpkg.B2).F | ||
// reachable (example.com/subpkg.C).F | ||
// reachable example.com/subpkg.NewInterfaceF | ||
// reachable example.com/subpkg.init | ||
// !reachable (*example.com/subpkg.D).F | ||
// !reachable (example.com/subpkg.D).F | ||
// reachable init | ||
// reachable main | ||
// reachable use | ||
// | ||
// rtype *example.com/subpkg.A | ||
// rtype *example.com/subpkg.B | ||
// rtype *example.com/subpkg.B2 | ||
// rtype *example.com/subpkg.C | ||
// rtype example.com/subpkg.B | ||
// rtype example.com/subpkg.A | ||
// rtype example.com/subpkg.B2 | ||
// rtype example.com/subpkg.C | ||
// !rtype example.com/subpkg.D | ||
|
||
-- subpkg/impl.go -- | ||
package subpkg | ||
|
||
type InterfaceF interface { | ||
F() | ||
} | ||
|
||
type A byte // instantiated but not a reflect type | ||
|
||
func (A) F() {} // reachable: exported method of reflect type | ||
|
||
type B int // a reflect type | ||
|
||
func (*B) F() {} // reachable: exported method of reflect type | ||
|
||
type B2 int // a reflect type, and *B2 also | ||
|
||
func (B2) F() {} // reachable: exported method of reflect type | ||
|
||
type C string | ||
|
||
func (C) F() {} // reachable: exported by NewInterfaceF | ||
|
||
func NewInterfaceF() InterfaceF { | ||
return C("") | ||
} | ||
|
||
type D uint // instantiated only in dead code | ||
|
||
func (*D) F() {} // unreachable |
6 changes: 4 additions & 2 deletions
6
go/callgraph/rta/testdata/reflectcall.go → go/callgraph/rta/testdata/reflectcall.txtar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
go/callgraph/rta/testdata/rtype.go → go/callgraph/rta/testdata/rtype.txtar
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters