Skip to content

Commit 78b8d11

Browse files
committed
C++: PR comments on DataFlow Position
1 parent a126154 commit 78b8d11

File tree

2 files changed

+47
-50
lines changed

2 files changed

+47
-50
lines changed

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

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,7 @@ private class SideEffectArgumentNode extends ArgumentNode {
7575

7676
override predicate argumentOf(DataFlowCall call, ArgumentPosition pos) {
7777
read.getPrimaryInstruction() = call and
78-
(
79-
pos.(IndirectionPosition).getIndex() = read.getIndex()
80-
)
78+
pos.(IndirectionPosition).getIndex() = read.getIndex()
8179
}
8280

8381
override string toString() {
@@ -94,6 +92,52 @@ private class SideEffectArgumentNode extends ArgumentNode {
9492
}
9593
}
9694

95+
/** A parameter position represented by an integer. */
96+
class ParameterPosition = Position;
97+
98+
/** An argument position represented by an integer. */
99+
class ArgumentPosition = Position;
100+
101+
class Position extends TPosition {
102+
abstract string toString();
103+
}
104+
105+
class DirectPosition extends TDirectPosition {
106+
int index;
107+
108+
DirectPosition() { this = TDirectPosition(index) }
109+
110+
string toString() {
111+
index = -1 and
112+
result = "this"
113+
or
114+
index != -1 and
115+
result = index.toString()
116+
}
117+
118+
int getIndex() { result = index }
119+
}
120+
121+
class IndirectionPosition extends TIndirectionPosition {
122+
int index;
123+
124+
IndirectionPosition() { this = TIndirectionPosition(index) }
125+
126+
string toString() {
127+
index = -1 and
128+
result = "this"
129+
or
130+
index != -1 and
131+
result = index.toString()
132+
}
133+
134+
int getIndex() { result = index }
135+
}
136+
137+
newtype TPosition =
138+
TDirectPosition(int index) { exists(any(CallInstruction c).getArgument(index))} or
139+
TIndirectionPosition(int index) { exists(ReadSideEffectInstruction instr | instr.getIndex() = index) }
140+
97141
private newtype TReturnKind =
98142
TNormalReturnKind() or
99143
TIndirectReturnKind(ParameterIndex index)

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

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ private import semmle.code.cpp.ir.IR
1111
private import semmle.code.cpp.controlflow.IRGuards
1212
private import semmle.code.cpp.models.interfaces.DataFlow
1313
private import DataFlowPrivate
14-
private import DataFlowDispatch
1514
private import SsaInternals as Ssa
1615

1716
cached
@@ -491,52 +490,6 @@ class ExprNode extends InstructionNode {
491490
override string toString() { result = this.asConvertedExpr().toString() }
492491
}
493492

494-
/** A parameter position represented by an integer. */
495-
class ParameterPosition = Position;
496-
497-
/** An argument position represented by an integer. */
498-
class ArgumentPosition = Position;
499-
500-
class Position extends TPosition {
501-
abstract string toString();
502-
}
503-
504-
class DirectPosition extends TDirectPosition {
505-
int index;
506-
507-
DirectPosition() { this = TDirectPosition(index) }
508-
509-
string toString() {
510-
index = -1 and
511-
result = "this"
512-
or
513-
index != -1 and
514-
result = index.toString()
515-
}
516-
517-
int getIndex() { result = index }
518-
}
519-
520-
class IndirectionPosition extends TIndirectionPosition {
521-
int index;
522-
523-
IndirectionPosition() { this = TIndirectionPosition(index) }
524-
525-
string toString() {
526-
index = -1 and
527-
result = "this"
528-
or
529-
index != -1 and
530-
result = index.toString()
531-
}
532-
533-
int getIndex() { result = index }
534-
}
535-
536-
newtype TPosition =
537-
TDirectPosition(int index) { exists(any(CallInstruction c).getArgument(index))} or
538-
TIndirectionPosition(int index) { exists(any(CallInstruction c).getArgument(index)) }
539-
540493
/**
541494
* The value of a parameter at function entry, viewed as a node in a data
542495
* flow graph. This includes both explicit parameters such as `x` in `f(x)`

0 commit comments

Comments
 (0)