Skip to content

Commit b874086

Browse files
committed
Fix FP in go/useless-assignment-to-local
1 parent 85adb81 commit b874086

2 files changed

Lines changed: 6 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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func deadParameter(x int) bool { // we don't want to flag x here
2727
}
2828

2929
func usedOnlyAfterFalse() bool {
30-
s := deadStore() // $ SPURIOUS: Alert
30+
s := deadStore()
3131
return false && s == 0
3232
}
3333

0 commit comments

Comments
 (0)