Skip to content

Commit 3784b18

Browse files
committed
changes based on review
1 parent 40fd182 commit 3784b18

File tree

2 files changed

+11
-26
lines changed

2 files changed

+11
-26
lines changed

javascript/ql/src/Declarations/DeadStoreOfLocal.ql

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,6 @@ predicate deadStoreOfLocal(VarDef vd, PurelyLocalVariable v) {
2929
not exists(SsaExplicitDefinition ssa | ssa.defines(vd, v))
3030
}
3131

32-
/**
33-
* Holds if there exists another definition of the variable `v` that dominates `dead`.
34-
*/
35-
predicate hasDominatingDef(VarDef dead, PurelyLocalVariable v) {
36-
exists(VarDef otherDef | not otherDef = dead and otherDef.getAVariable() = v |
37-
dead.getBasicBlock().getASuccessor+() = otherDef.getBasicBlock()
38-
or
39-
exists(ReachableBasicBlock bb, int i, int j |
40-
bb = otherDef.getBasicBlock() and bb = dead.getBasicBlock()
41-
|
42-
bb.defAt(i, v, dead) and
43-
bb.defAt(j, v, otherDef) and
44-
j > i
45-
)
46-
)
47-
}
48-
4932
from VarDef dead, PurelyLocalVariable v, string msg
5033
where
5134
deadStoreOfLocal(dead, v) and
@@ -80,8 +63,10 @@ where
8063
(
8164
// To avoid confusion about the meaning of "definition" and "declaration" we avoid
8265
// the term "definition" when the alert location is a variable declaration.
83-
if dead instanceof VariableDeclarator and hasDominatingDef(dead, v)
66+
if
67+
dead instanceof VariableDeclarator and
68+
not exists(SsaImplicitInit init | init.getVariable().getSourceVariable() = v) // the variable is dead at the hoisted implicit initialization.
8469
then msg = "The initial value of " + v.getName() + " is unused, since it is always overwritten."
85-
else msg = "This definition of " + v.getName() + " is useless, since its value is never read."
70+
else msg = "The value assigned to " + v.getName() + " here is unused."
8671
)
8772
select dead, msg
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
| overload.ts:10:12:10:14 | baz | This definition of baz is useless, since its value is never read. |
1+
| overload.ts:10:12:10:14 | baz | The value assigned to baz here is unused. |
22
| tst2.js:26:9:26:14 | x = 23 | The initial value of x is unused, since it is always overwritten. |
3-
| tst2.js:28:9:28:14 | x = 42 | This definition of x is useless, since its value is never read. |
4-
| tst3.js:2:1:2:36 | exports ... a: 23 } | This definition of exports is useless, since its value is never read. |
5-
| tst3b.js:2:18:2:36 | exports = { a: 23 } | This definition of exports is useless, since its value is never read. |
6-
| tst.js:6:2:6:7 | y = 23 | This definition of y is useless, since its value is never read. |
3+
| tst2.js:28:9:28:14 | x = 42 | The value assigned to x here is unused. |
4+
| tst3.js:2:1:2:36 | exports ... a: 23 } | The value assigned to exports here is unused. |
5+
| tst3b.js:2:18:2:36 | exports = { a: 23 } | The value assigned to exports here is unused. |
6+
| tst.js:6:2:6:7 | y = 23 | The value assigned to y here is unused. |
77
| tst.js:13:6:13:11 | a = 23 | The initial value of a is unused, since it is always overwritten. |
8-
| tst.js:13:14:13:19 | a = 42 | This definition of a is useless, since its value is never read. |
8+
| tst.js:13:14:13:19 | a = 42 | The value assigned to a here is unused. |
99
| tst.js:45:6:45:11 | x = 23 | The initial value of x is unused, since it is always overwritten. |
1010
| tst.js:51:6:51:11 | x = 23 | The initial value of x is unused, since it is always overwritten. |
1111
| tst.js:132:7:132:13 | {x} = o | The initial value of x is unused, since it is always overwritten. |
1212
| tst.js:162:6:162:14 | [x] = [0] | The initial value of x is unused, since it is always overwritten. |
13-
| tst.js:172:7:172:17 | nSign = foo | This definition of nSign is useless, since its value is never read. |
13+
| tst.js:172:7:172:17 | nSign = foo | The value assigned to nSign here is unused. |

0 commit comments

Comments
 (0)