Skip to content

Commit 5f76caf

Browse files
authored
Merge pull request #13672 from owen-mc/go/make-parameter-nodes-for-unused-parameters-2
Go: make `ParameterNode`s for unused parameters #2 (make a disjoint class for unused ones)
2 parents af5cd7c + 972aacc commit 5f76caf

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Parameter nodes now exist for unused parameters as well as used parameters.

go/ql/lib/semmle/go/dataflow/internal/DataFlowNodes.qll

+18
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,24 @@ module Public {
680680
}
681681
}
682682

683+
/** A representation of a parameter initialization, defined in source via an SSA node. */
684+
class UnusedParameterNode extends ParameterNode, InstructionNode {
685+
override IR::InitParameterInstruction insn;
686+
Parameter parm;
687+
688+
UnusedParameterNode() {
689+
insn = IR::initParamInstruction(parm) and
690+
not exists(SsaExplicitDefinition ssa | ssa.getInstruction() = insn)
691+
}
692+
693+
/** Gets the parameter this node initializes. */
694+
override Parameter asParameter() { result = parm }
695+
696+
override predicate isParameterOf(DataFlowCallable c, int i) {
697+
parm.isParameterOf(c.asCallable().getFuncDef(), i)
698+
}
699+
}
700+
683701
/** A representation of a parameter initialization, defined in source via an SSA node. */
684702
class SsaParameterNode extends ParameterNode, SsaNode {
685703
override SsaExplicitDefinition ssa;

go/ql/test/library-tests/semmle/go/dataflow/FunctionInputsAndOutputs/FunctionInput_getExitNode.expected

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
| parameter 0 | reset.go:8:1:16:1 | function declaration | reset.go:8:27:8:27 | definition of r |
55
| parameter 0 | tst2.go:8:1:12:1 | function declaration | tst2.go:8:12:8:15 | definition of data |
66
| parameter 0 | tst.go:8:1:11:1 | function declaration | tst.go:8:12:8:17 | definition of reader |
7+
| parameter 0 | tst.go:13:1:13:25 | function declaration | tst.go:13:12:13:13 | initialization of xs |
78
| parameter 0 | tst.go:15:1:19:1 | function declaration | tst.go:15:12:15:12 | definition of x |
89
| parameter 1 | main.go:5:1:11:1 | function declaration | main.go:5:20:5:20 | definition of x |
910
| parameter 1 | main.go:13:1:20:1 | function declaration | main.go:13:21:13:21 | definition of x |

0 commit comments

Comments
 (0)