mirror of
https://github.com/github/codeql.git
synced 2026-01-29 22:32:58 +01:00
Remove Entity.getAUse() and replace uses with getAReference().
The former had result type `Ident`, so it wouldn't pick up references to methods and fields. Apart from that, it is subsumed by the latter anyway.
This commit is contained in:
@@ -23,9 +23,9 @@ import go
|
||||
* downward.
|
||||
*/
|
||||
predicate bounds(RelationalComparisonExpr test, Variable v, string direction) {
|
||||
test.getLesserOperand() = v.getAUse() and direction = "upward"
|
||||
test.getLesserOperand() = v.getAReference() and direction = "upward"
|
||||
or
|
||||
test.getGreaterOperand() = v.getAUse() and direction = "downward"
|
||||
test.getGreaterOperand() = v.getAReference() and direction = "downward"
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -36,7 +36,7 @@ predicate bounds(RelationalComparisonExpr test, Variable v, string direction) {
|
||||
* downward.
|
||||
*/
|
||||
predicate updates(IncDecStmt upd, Variable v, string direction) {
|
||||
upd.getExpr() = v.getAUse() and
|
||||
upd.getExpr() = v.getAReference() and
|
||||
(
|
||||
upd instanceof IncStmt and direction = "upward"
|
||||
or
|
||||
|
||||
@@ -36,7 +36,7 @@ where
|
||||
// exclude assignments with default values or simple expressions
|
||||
not isSimple(rhs) and
|
||||
// exclude variables that are not used at all
|
||||
exists(target.getAUse()) and
|
||||
exists(target.getAReference()) and
|
||||
// exclude variables with indirect references
|
||||
not target.mayHaveIndirectReferences()
|
||||
select def, "This definition of " + target + " is never used."
|
||||
|
||||
@@ -116,9 +116,6 @@ class Entity extends @object {
|
||||
/** Gets the declaring identifier for this entity. */
|
||||
Ident getDeclaration() { result.declares(this) }
|
||||
|
||||
/** Gets an identifier in rvalue position that refers to this entity. */
|
||||
Ident getAUse() { result.uses(this) }
|
||||
|
||||
/** Gets a reference to this entity. */
|
||||
Name getAReference() { result.getTarget() = this }
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ module IR {
|
||||
/** Gets the expression underlying this instruction. */
|
||||
Expr getExpr() { result = e }
|
||||
|
||||
override predicate reads(ValueEntity v) { e = v.getAUse() }
|
||||
override predicate reads(ValueEntity v) { e = v.getAReference() }
|
||||
|
||||
override Type getResultType() { result = e.getType() }
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class SsaSourceVariable extends LocalVariable {
|
||||
*/
|
||||
predicate mayHaveIndirectReferences() {
|
||||
// variables that have their address taken
|
||||
exists(AddressExpr addr | addr.getOperand().stripParens() = getAUse())
|
||||
exists(AddressExpr addr | addr.getOperand().stripParens() = getAReference())
|
||||
or
|
||||
exists(DataFlow::MethodReadNode mrn |
|
||||
mrn.getReceiver() = getARead() and
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
| a | types.go:24:22:24:22 | a |
|
||||
| bump | main.go:23:16:23:19 | bump |
|
||||
| foo | main.go:17:6:17:8 | foo |
|
||||
| iHaveAMethod | types.go:3:6:3:17 | iHaveAMethod |
|
||||
| main | main.go:9:6:9:9 | main |
|
||||
@@ -12,6 +13,7 @@
|
||||
| meth2 | types.go:28:16:28:20 | meth2 |
|
||||
| notImpl | types.go:22:6:22:12 | notImpl |
|
||||
| recv | main.go:13:7:13:10 | recv |
|
||||
| recv | main.go:23:7:23:10 | recv |
|
||||
| starImpl | types.go:12:6:12:13 | starImpl |
|
||||
| t | main.go:5:6:5:6 | t |
|
||||
| twoMethods | types.go:7:6:7:15 | twoMethods |
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
| Println | <library> | main.go:10:2:10:12 | selection of Println |
|
||||
| Println | <library> | main.go:10:6:10:12 | Println |
|
||||
| a | types.go@24:22-24:22 | types.go:24:22:24:22 | a |
|
||||
| a | types.go@24:22-24:22 | types.go:25:9:25:9 | a |
|
||||
| bool | <library> | types.go:8:10:8:13 | bool |
|
||||
| bool | <library> | types.go:14:26:14:29 | bool |
|
||||
| bool | <library> | types.go:24:29:24:32 | bool |
|
||||
| bump | main.go@23:16-23:19 | main.go:23:16:23:19 | bump |
|
||||
| false | <library> | types.go:15:9:15:13 | false |
|
||||
| fmt | <library> | main.go:10:2:10:4 | fmt |
|
||||
| foo | main.go@17:6-17:8 | main.go:17:6:17:8 | foo |
|
||||
| iHaveAMethod | types.go@3:6-3:17 | main.go:17:12:17:23 | iHaveAMethod |
|
||||
| iHaveAMethod | types.go@3:6-3:17 | types.go:3:6:3:17 | iHaveAMethod |
|
||||
| int | <library> | main.go:6:4:6:6 | int |
|
||||
| int | <library> | main.go:13:23:13:25 | int |
|
||||
| int | <library> | types.go:4:9:4:11 | int |
|
||||
| int | <library> | types.go:9:10:9:12 | int |
|
||||
| int | <library> | types.go:18:25:18:27 | int |
|
||||
| int | <library> | types.go:24:24:24:26 | int |
|
||||
| int | <library> | types.go:28:24:28:26 | int |
|
||||
| main | main.go@9:6-9:9 | main.go:9:6:9:9 | main |
|
||||
| meth | main.go@13:16-13:19 | main.go:13:16:13:19 | meth |
|
||||
| meth | main.go@13:16-13:19 | main.go:19:2:19:7 | selection of meth |
|
||||
| meth | main.go@13:16-13:19 | main.go:19:4:19:7 | meth |
|
||||
| meth | main.go@13:16-13:19 | main.go:20:2:20:10 | selection of meth |
|
||||
| meth | main.go@13:16-13:19 | main.go:20:7:20:10 | meth |
|
||||
| meth | types.go@4:2-4:5 | main.go:18:2:18:7 | selection of meth |
|
||||
| meth | types.go@4:2-4:5 | main.go:18:4:18:7 | meth |
|
||||
| meth | types.go@4:2-4:5 | types.go:4:2:4:5 | meth |
|
||||
| meth1 | types.go@8:2-8:6 | types.go:8:2:8:6 | meth1 |
|
||||
| meth1 | types.go@14:18-14:22 | types.go:14:18:14:22 | meth1 |
|
||||
| meth1 | types.go@24:16-24:20 | types.go:24:16:24:20 | meth1 |
|
||||
| meth2 | types.go@9:2-9:6 | types.go:9:2:9:6 | meth2 |
|
||||
| meth2 | types.go@18:17-18:21 | types.go:18:17:18:21 | meth2 |
|
||||
| meth2 | types.go@28:16-28:20 | types.go:28:16:28:20 | meth2 |
|
||||
| notImpl | types.go@22:6-22:12 | types.go:22:6:22:12 | notImpl |
|
||||
| notImpl | types.go@22:6-22:12 | types.go:24:7:24:13 | notImpl |
|
||||
| notImpl | types.go@22:6-22:12 | types.go:28:7:28:13 | notImpl |
|
||||
| recv | main.go@13:7-13:10 | main.go:13:7:13:10 | recv |
|
||||
| recv | main.go@13:7-13:10 | main.go:14:9:14:12 | recv |
|
||||
| recv | main.go@23:7-23:10 | main.go:23:7:23:10 | recv |
|
||||
| recv | main.go@23:7-23:10 | main.go:24:2:24:5 | recv |
|
||||
| starImpl | types.go@12:6-12:13 | types.go:12:6:12:13 | starImpl |
|
||||
| starImpl | types.go@12:6-12:13 | types.go:14:8:14:15 | starImpl |
|
||||
| starImpl | types.go@12:6-12:13 | types.go:18:7:18:14 | starImpl |
|
||||
| t | main.go@5:6-5:6 | main.go:5:6:5:6 | t |
|
||||
| t | main.go@5:6-5:6 | main.go:13:13:13:13 | t |
|
||||
| t | main.go@5:6-5:6 | main.go:17:29:17:29 | t |
|
||||
| t | main.go@5:6-5:6 | main.go:20:4:20:4 | t |
|
||||
| t | main.go@5:6-5:6 | main.go:23:13:23:13 | t |
|
||||
| twoMethods | types.go@7:6-7:15 | types.go:7:6:7:15 | twoMethods |
|
||||
| x | main.go@6:2-6:2 | main.go:6:2:6:2 | x |
|
||||
| x | main.go@6:2-6:2 | main.go:14:9:14:14 | selection of x |
|
||||
| x | main.go@6:2-6:2 | main.go:14:14:14:14 | x |
|
||||
| x | main.go@6:2-6:2 | main.go:24:2:24:7 | selection of x |
|
||||
| x | main.go@6:2-6:2 | main.go:24:7:24:7 | x |
|
||||
| x | main.go@17:10-17:10 | main.go:17:10:17:10 | x |
|
||||
| x | main.go@17:10-17:10 | main.go:18:2:18:2 | x |
|
||||
| y | main.go@17:26-17:26 | main.go:17:26:17:26 | y |
|
||||
| y | main.go@17:26-17:26 | main.go:19:2:19:2 | y |
|
||||
| y | main.go@17:26-17:26 | main.go:20:12:20:12 | y |
|
||||
@@ -6,4 +6,4 @@ where
|
||||
or
|
||||
not exists(e.getDeclaration()) and
|
||||
declloc = "<library>"
|
||||
select e, declloc, e.getAUse()
|
||||
select e, declloc, e.getAReference()
|
||||
@@ -1,4 +1,5 @@
|
||||
| a | int |
|
||||
| bump | func() |
|
||||
| foo | func(iHaveAMethod, * t) |
|
||||
| iHaveAMethod | iHaveAMethod |
|
||||
| main | func() |
|
||||
@@ -12,6 +13,7 @@
|
||||
| meth2 | func() int |
|
||||
| notImpl | notImpl |
|
||||
| recv | * t |
|
||||
| recv | * t |
|
||||
| starImpl | starImpl |
|
||||
| t | t |
|
||||
| twoMethods | twoMethods |
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
| Println | <library> | main.go:10:6:10:12 | Println |
|
||||
| a | types.go@24:22-24:22 | types.go:25:9:25:9 | a |
|
||||
| bool | <library> | types.go:8:10:8:13 | bool |
|
||||
| bool | <library> | types.go:14:26:14:29 | bool |
|
||||
| bool | <library> | types.go:24:29:24:32 | bool |
|
||||
| false | <library> | types.go:15:9:15:13 | false |
|
||||
| fmt | <library> | main.go:10:2:10:4 | fmt |
|
||||
| iHaveAMethod | types.go@3:6-3:17 | main.go:17:12:17:23 | iHaveAMethod |
|
||||
| int | <library> | main.go:6:4:6:6 | int |
|
||||
| int | <library> | main.go:13:23:13:25 | int |
|
||||
| int | <library> | types.go:4:9:4:11 | int |
|
||||
| int | <library> | types.go:9:10:9:12 | int |
|
||||
| int | <library> | types.go:18:25:18:27 | int |
|
||||
| int | <library> | types.go:24:24:24:26 | int |
|
||||
| int | <library> | types.go:28:24:28:26 | int |
|
||||
| meth | main.go@13:16-13:19 | main.go:19:4:19:7 | meth |
|
||||
| meth | main.go@13:16-13:19 | main.go:20:7:20:10 | meth |
|
||||
| meth | types.go@4:2-4:5 | main.go:18:4:18:7 | meth |
|
||||
| notImpl | types.go@22:6-22:12 | types.go:24:7:24:13 | notImpl |
|
||||
| notImpl | types.go@22:6-22:12 | types.go:28:7:28:13 | notImpl |
|
||||
| recv | main.go@13:7-13:10 | main.go:14:9:14:12 | recv |
|
||||
| starImpl | types.go@12:6-12:13 | types.go:14:8:14:15 | starImpl |
|
||||
| starImpl | types.go@12:6-12:13 | types.go:18:7:18:14 | starImpl |
|
||||
| t | main.go@5:6-5:6 | main.go:13:13:13:13 | t |
|
||||
| t | main.go@5:6-5:6 | main.go:17:29:17:29 | t |
|
||||
| t | main.go@5:6-5:6 | main.go:20:4:20:4 | t |
|
||||
| x | main.go@6:2-6:2 | main.go:14:14:14:14 | x |
|
||||
| x | main.go@17:10-17:10 | main.go:18:2:18:2 | x |
|
||||
| y | main.go@17:26-17:26 | main.go:19:2:19:2 | y |
|
||||
| y | main.go@17:26-17:26 | main.go:20:12:20:12 | y |
|
||||
@@ -1,3 +1,4 @@
|
||||
| bump | github.com/Semmle/go/ql/test/library-tests/semmle/go/Scopes.t.bump | recv | * t |
|
||||
| meth | github.com/Semmle/go/ql/test/library-tests/semmle/go/Scopes.iHaveAMethod.meth | | iHaveAMethod |
|
||||
| meth | github.com/Semmle/go/ql/test/library-tests/semmle/go/Scopes.t.meth | recv | * t |
|
||||
| meth1 | github.com/Semmle/go/ql/test/library-tests/semmle/go/Scopes.notImpl.meth1 | | notImpl |
|
||||
|
||||
@@ -19,3 +19,7 @@ func foo(x iHaveAMethod, y *t) {
|
||||
y.meth()
|
||||
(*t).meth(y)
|
||||
}
|
||||
|
||||
func (recv *t) bump() {
|
||||
recv.x++
|
||||
}
|
||||
|
||||
@@ -27,4 +27,5 @@
|
||||
| main.go:84:9:84:9 | x | x |
|
||||
| main.go:84:15:84:15 | x | x |
|
||||
| main.go:94:2:94:8 | wrapper | wrapper |
|
||||
| main.go:94:2:94:10 | selection of s | s |
|
||||
| main.go:97:9:97:9 | x | x |
|
||||
|
||||
Reference in New Issue
Block a user