Skip to content

Commit a94601c

Browse files
committed
Add test checking for entity counts and def-use matches under aliasing
1 parent ea1870f commit a94601c

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package aliases
2+
3+
type IntAlias = int
4+
5+
type S1 = struct{ x int }
6+
type S2 = struct{ x IntAlias }
7+
8+
func Test1() int {
9+
obj := S1{1}
10+
obj.x = 2
11+
12+
var ptr *S2
13+
ptr = &S1
14+
15+
return ptr.x
16+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
lowLevelDefs
2+
| defsuses.go:3:6:3:13 | IntAlias | defsuses.go:3:6:3:13 | IntAlias (1 declaration sites) |
3+
| defsuses.go:5:6:5:7 | S1 | defsuses.go:5:6:5:7 | S1 (1 declaration sites) |
4+
| defsuses.go:5:20:5:20 | x | defsuses.go:5:20:5:20 | x (2 declaration sites) |
5+
| defsuses.go:5:20:5:20 | x | defsuses.go:6:20:6:20 | x (2 declaration sites) |
6+
| defsuses.go:6:6:6:7 | S2 | defsuses.go:6:6:6:7 | S2 (1 declaration sites) |
7+
| defsuses.go:6:20:6:20 | x | defsuses.go:5:20:5:20 | x (2 declaration sites) |
8+
| defsuses.go:6:20:6:20 | x | defsuses.go:6:20:6:20 | x (2 declaration sites) |
9+
| defsuses.go:8:6:8:10 | Test1 | defsuses.go:8:6:8:10 | Test1 (1 declaration sites) |
10+
| defsuses.go:9:2:9:4 | obj | defsuses.go:9:2:9:4 | obj (1 declaration sites) |
11+
| defsuses.go:12:6:12:8 | ptr | defsuses.go:12:6:12:8 | ptr (1 declaration sites) |
12+
lowLevelUses
13+
| defsuses.go:3:17:3:19 | int | file://:0:0:0:0 | int (0 declaration sites) |
14+
| defsuses.go:5:22:5:24 | int | file://:0:0:0:0 | int (0 declaration sites) |
15+
| defsuses.go:6:22:6:29 | IntAlias | defsuses.go:3:6:3:13 | IntAlias (1 declaration sites) |
16+
| defsuses.go:8:14:8:16 | int | file://:0:0:0:0 | int (0 declaration sites) |
17+
| defsuses.go:9:9:9:10 | S1 | defsuses.go:5:6:5:7 | S1 (1 declaration sites) |
18+
| defsuses.go:10:2:10:4 | obj | defsuses.go:9:2:9:4 | obj (1 declaration sites) |
19+
| defsuses.go:10:6:10:6 | x | defsuses.go:5:20:5:20 | x (2 declaration sites) |
20+
| defsuses.go:10:6:10:6 | x | defsuses.go:6:20:6:20 | x (2 declaration sites) |
21+
| defsuses.go:12:11:12:12 | S2 | defsuses.go:6:6:6:7 | S2 (1 declaration sites) |
22+
| defsuses.go:13:2:13:4 | ptr | defsuses.go:12:6:12:8 | ptr (1 declaration sites) |
23+
| defsuses.go:13:9:13:10 | S1 | defsuses.go:5:6:5:7 | S1 (1 declaration sites) |
24+
| defsuses.go:15:9:15:11 | ptr | defsuses.go:12:6:12:8 | ptr (1 declaration sites) |
25+
| defsuses.go:15:13:15:13 | x | defsuses.go:5:20:5:20 | x (2 declaration sites) |
26+
| defsuses.go:15:13:15:13 | x | defsuses.go:6:20:6:20 | x (2 declaration sites) |
27+
distinctDefinedXs
28+
| 1 |
29+
distinctUsedXs
30+
| 1 |
31+
fieldUseUsePairs
32+
| defsuses.go:10:6:10:6 | x | defsuses.go:15:13:15:13 | x |
33+
| defsuses.go:15:13:15:13 | x | defsuses.go:10:6:10:6 | x |
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import go
2+
3+
newtype TEntityWithDeclInfo = MkEntityWithDeclInfo(Entity e)
4+
5+
class EntityWithDeclInfo extends TEntityWithDeclInfo {
6+
string toString() {
7+
exists(Entity e | this = MkEntityWithDeclInfo(e) |
8+
result = e.toString() + " (" + count(e.getDeclaration()) + " declaration sites)"
9+
)
10+
}
11+
12+
predicate hasLocationInfo(
13+
string filepath, int startline, int startcolumn, int endline, int endcolumn
14+
) {
15+
exists(Entity e | this = MkEntityWithDeclInfo(e) |
16+
e.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
17+
)
18+
}
19+
}
20+
21+
query predicate lowLevelDefs(Ident i, EntityWithDeclInfo ewrapped) {
22+
exists(Entity e | ewrapped = MkEntityWithDeclInfo(e) | defs(i, e))
23+
}
24+
25+
query predicate lowLevelUses(Ident i, EntityWithDeclInfo ewrapped) {
26+
exists(Entity e | ewrapped = MkEntityWithDeclInfo(e) | uses(i, e))
27+
}
28+
29+
query predicate distinctDefinedXs(int ct) {
30+
ct = count(Entity e | defs(_, e) and e.toString() = "x")
31+
}
32+
33+
query predicate distinctUsedXs(int ct) { ct = count(Entity e | uses(_, e) and e.toString() = "x") }
34+
35+
query predicate fieldUseUsePairs(Ident i1, Ident i2) {
36+
exists(Field e | uses(i1, e) and uses(i2, e) and i1 != i2)
37+
}

0 commit comments

Comments
 (0)