Skip to content

Commit eb35fa0

Browse files
committed
C++: Unify 'isSourceParameterOf' for this parameters with the implementation for positional parameters.
1 parent 8349bd5 commit eb35fa0

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowNodes.qll

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -850,11 +850,6 @@ module Public {
850850
{
851851
ThisParameterInstructionNode() { instr.getIRVariable() instanceof IRThisVariable }
852852

853-
override predicate isSourceParameterOf(Function f, ParameterPosition pos) {
854-
pos.(DirectPosition).getArgumentIndex() = -1 and
855-
instr.getEnclosingFunction() = f
856-
}
857-
858853
override string toStringImpl() { result = "this" }
859854
}
860855

@@ -1659,6 +1654,11 @@ abstract private class AbstractParameterNode extends Node {
16591654

16601655
/** Gets the `Parameter` associated with this node, if it exists. */
16611656
Parameter getParameter() { none() } // overridden by subclasses
1657+
1658+
/**
1659+
* Holds if this node represents an implicit `this` parameter, if it exists.
1660+
*/
1661+
predicate isThis() { none() } // overridden by subclasses
16621662
}
16631663

16641664
abstract private class AbstractIndirectParameterNode extends AbstractParameterNode {
@@ -1701,9 +1701,10 @@ private class IndirectInstructionParameterNode extends AbstractIndirectParameter
17011701
)
17021702
}
17031703

1704-
/** Gets the parameter whose indirection is initialized. */
17051704
override Parameter getParameter() { result = init.getParameter() }
17061705

1706+
override predicate isThis() { init.hasIndex(-1) }
1707+
17071708
override DataFlowCallable getEnclosingCallable() {
17081709
result.asSourceCallable() = this.getFunction()
17091710
}
@@ -1738,6 +1739,18 @@ abstract class InstructionDirectParameterNode extends InstructionNode, AbstractD
17381739
* Gets the `IRVariable` that this parameter references.
17391740
*/
17401741
final IRVariable getIRVariable() { result = instr.getIRVariable() }
1742+
1743+
override predicate isThis() { instr.hasIndex(-1) }
1744+
1745+
override Parameter getParameter() { result = instr.getParameter() }
1746+
1747+
override predicate isSourceParameterOf(Function f, ParameterPosition pos) {
1748+
this.getFunction() = f and
1749+
exists(int argumentIndex |
1750+
pos.(DirectPosition).getArgumentIndex() = argumentIndex and
1751+
instr.hasIndex(argumentIndex)
1752+
)
1753+
}
17411754
}
17421755

17431756
abstract private class AbstractExplicitParameterNode extends AbstractDirectParameterNode { }
@@ -1748,13 +1761,7 @@ private class ExplicitParameterInstructionNode extends AbstractExplicitParameter
17481761
{
17491762
ExplicitParameterInstructionNode() { exists(instr.getParameter()) }
17501763

1751-
override predicate isSourceParameterOf(Function f, ParameterPosition pos) {
1752-
f.getParameter(pos.(DirectPosition).getArgumentIndex()) = instr.getParameter()
1753-
}
1754-
17551764
override string toStringImpl() { result = instr.getParameter().toString() }
1756-
1757-
override Parameter getParameter() { result = instr.getParameter() }
17581765
}
17591766

17601767
/**

0 commit comments

Comments
 (0)