Skip to content

Commit 1d6ad81

Browse files
authored
Merge pull request #22610 from owen-mc/go/fix/dead-store-of-local
Go: fix FP in `go/dead-store-of-local`
2 parents 39547c7 + b874086 commit 1d6ad81

3 files changed

Lines changed: 11 additions & 3 deletions

File tree

go/ql/src/RedundantCode/DeadStoreOfLocal.ql

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ where
3737
def.getBasicBlock() instanceof ReachableBasicBlock and
3838
// exclude assignments with default values or simple expressions
3939
not isSimple(rhs) and
40-
// exclude variables that are not used at all
41-
exists(target.getAReference()) and
40+
// exclude variables that are not used in reachable code
41+
exists(IR::Instruction ref |
42+
ref != def and
43+
(ref.reads(target) or ref.writes(target, _))
44+
) and
4245
// exclude variables with indirect references
4346
not target.mayHaveIndirectReferences() and
4447
// Report the assigned variable rather than the whole write instruction. A write to an
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
| main.go:36:9:36:9 | undefined: unknownFunction |
1+
| main.go:41:9:41:9 | undefined: unknownFunction |

go/ql/test/query-tests/RedundantCode/DeadStoreOfLocal/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ func deadParameter(x int) bool { // we don't want to flag x here
2626
return true
2727
}
2828

29+
func usedOnlyAfterFalse() bool {
30+
s := deadStore()
31+
return false && s == 0
32+
}
33+
2934
func test2(x int) (int, int) {
3035
y := x >> 5
3136
z := x % (1)

0 commit comments

Comments
 (0)