Add test checking for entity counts and def-use matches under aliasing

This commit is contained in:
Chris Smowton 2024-09-03 17:56:24 +01:00
Родитель ea1870fbbd
Коммит a94601c8c0
3 изменённых файлов: 86 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,16 @@
package aliases
type IntAlias = int
type S1 = struct{ x int }
type S2 = struct{ x IntAlias }
func Test1() int {
obj := S1{1}
obj.x = 2
var ptr *S2
ptr = &S1
return ptr.x
}

Просмотреть файл

@ -0,0 +1,33 @@
lowLevelDefs
| defsuses.go:3:6:3:13 | IntAlias | defsuses.go:3:6:3:13 | IntAlias (1 declaration sites) |
| defsuses.go:5:6:5:7 | S1 | defsuses.go:5:6:5:7 | S1 (1 declaration sites) |
| defsuses.go:5:20:5:20 | x | defsuses.go:5:20:5:20 | x (2 declaration sites) |
| defsuses.go:5:20:5:20 | x | defsuses.go:6:20:6:20 | x (2 declaration sites) |
| defsuses.go:6:6:6:7 | S2 | defsuses.go:6:6:6:7 | S2 (1 declaration sites) |
| defsuses.go:6:20:6:20 | x | defsuses.go:5:20:5:20 | x (2 declaration sites) |
| defsuses.go:6:20:6:20 | x | defsuses.go:6:20:6:20 | x (2 declaration sites) |
| defsuses.go:8:6:8:10 | Test1 | defsuses.go:8:6:8:10 | Test1 (1 declaration sites) |
| defsuses.go:9:2:9:4 | obj | defsuses.go:9:2:9:4 | obj (1 declaration sites) |
| defsuses.go:12:6:12:8 | ptr | defsuses.go:12:6:12:8 | ptr (1 declaration sites) |
lowLevelUses
| defsuses.go:3:17:3:19 | int | file://:0:0:0:0 | int (0 declaration sites) |
| defsuses.go:5:22:5:24 | int | file://:0:0:0:0 | int (0 declaration sites) |
| defsuses.go:6:22:6:29 | IntAlias | defsuses.go:3:6:3:13 | IntAlias (1 declaration sites) |
| defsuses.go:8:14:8:16 | int | file://:0:0:0:0 | int (0 declaration sites) |
| defsuses.go:9:9:9:10 | S1 | defsuses.go:5:6:5:7 | S1 (1 declaration sites) |
| defsuses.go:10:2:10:4 | obj | defsuses.go:9:2:9:4 | obj (1 declaration sites) |
| defsuses.go:10:6:10:6 | x | defsuses.go:5:20:5:20 | x (2 declaration sites) |
| defsuses.go:10:6:10:6 | x | defsuses.go:6:20:6:20 | x (2 declaration sites) |
| defsuses.go:12:11:12:12 | S2 | defsuses.go:6:6:6:7 | S2 (1 declaration sites) |
| defsuses.go:13:2:13:4 | ptr | defsuses.go:12:6:12:8 | ptr (1 declaration sites) |
| defsuses.go:13:9:13:10 | S1 | defsuses.go:5:6:5:7 | S1 (1 declaration sites) |
| defsuses.go:15:9:15:11 | ptr | defsuses.go:12:6:12:8 | ptr (1 declaration sites) |
| defsuses.go:15:13:15:13 | x | defsuses.go:5:20:5:20 | x (2 declaration sites) |
| defsuses.go:15:13:15:13 | x | defsuses.go:6:20:6:20 | x (2 declaration sites) |
distinctDefinedXs
| 1 |
distinctUsedXs
| 1 |
fieldUseUsePairs
| defsuses.go:10:6:10:6 | x | defsuses.go:15:13:15:13 | x |
| defsuses.go:15:13:15:13 | x | defsuses.go:10:6:10:6 | x |

Просмотреть файл

@ -0,0 +1,37 @@
import go
newtype TEntityWithDeclInfo = MkEntityWithDeclInfo(Entity e)
class EntityWithDeclInfo extends TEntityWithDeclInfo {
string toString() {
exists(Entity e | this = MkEntityWithDeclInfo(e) |
result = e.toString() + " (" + count(e.getDeclaration()) + " declaration sites)"
)
}
predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn
) {
exists(Entity e | this = MkEntityWithDeclInfo(e) |
e.hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
)
}
}
query predicate lowLevelDefs(Ident i, EntityWithDeclInfo ewrapped) {
exists(Entity e | ewrapped = MkEntityWithDeclInfo(e) | defs(i, e))
}
query predicate lowLevelUses(Ident i, EntityWithDeclInfo ewrapped) {
exists(Entity e | ewrapped = MkEntityWithDeclInfo(e) | uses(i, e))
}
query predicate distinctDefinedXs(int ct) {
ct = count(Entity e | defs(_, e) and e.toString() = "x")
}
query predicate distinctUsedXs(int ct) { ct = count(Entity e | uses(_, e) and e.toString() = "x") }
query predicate fieldUseUsePairs(Ident i1, Ident i2) {
exists(Field e | uses(i1, e) and uses(i2, e) and i1 != i2)
}