Skip to content

Commit e5ce27f

Browse files
committed
C++: Fix a number of instances where a dataflow node did not have a location
1 parent 31fa230 commit e5ce27f

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,11 @@ class InstructionNode extends Node0 {
405405
/** Gets the instruction corresponding to this node. */
406406
Instruction getInstruction() { result = instr }
407407

408-
override Location getLocationImpl() { result = instr.getAst().getLocation() }
408+
override Location getLocationImpl() {
409+
if exists(instr.getAst().getLocation())
410+
then result = instr.getAst().getLocation()
411+
else result instanceof UnknownDefaultLocation
412+
}
409413

410414
override string toStringImpl() {
411415
if instr.(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable
@@ -426,7 +430,11 @@ class OperandNode extends Node, Node0 {
426430
/** Gets the operand corresponding to this node. */
427431
Operand getOperand() { result = op }
428432

429-
override Location getLocationImpl() { result = op.getDef().getAst().getLocation() }
433+
override Location getLocationImpl() {
434+
if exists(op.getDef().getAst().getLocation())
435+
then result = op.getDef().getAst().getLocation()
436+
else result instanceof UnknownDefaultLocation
437+
}
430438

431439
override string toStringImpl() {
432440
if op.getDef().(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable
@@ -641,6 +649,8 @@ class IndirectParameterNode extends Node, IndirectInstruction {
641649

642650
override Declaration getFunction() { result = this.getInstruction().getEnclosingFunction() }
643651

652+
override Location getLocationImpl() { result = this.getParameter().getLocation() }
653+
644654
override string toStringImpl() {
645655
result = this.getParameter().toString() + " indirection"
646656
or
@@ -888,7 +898,11 @@ class RawIndirectOperand extends Node, TRawIndirectOperand {
888898
)
889899
}
890900

891-
final override Location getLocationImpl() { result = this.getOperand().getLocation() }
901+
final override Location getLocationImpl() {
902+
if exists(this.getOperand().getLocation())
903+
then result = this.getOperand().getLocation()
904+
else result instanceof UnknownDefaultLocation
905+
}
892906

893907
override string toStringImpl() {
894908
result = instructionNode(this.getOperand().getDef()).toStringImpl() + " indirection"
@@ -987,7 +1001,11 @@ class RawIndirectInstruction extends Node, TRawIndirectInstruction {
9871001
)
9881002
}
9891003

990-
final override Location getLocationImpl() { result = this.getInstruction().getLocation() }
1004+
final override Location getLocationImpl() {
1005+
if exists(this.getInstruction().getLocation())
1006+
then result = this.getInstruction().getLocation()
1007+
else result instanceof UnknownDefaultLocation
1008+
}
9911009

9921010
override string toStringImpl() {
9931011
result = instructionNode(this.getInstruction()).toStringImpl() + " indirection"

cpp/ql/test/library-tests/syntax-zoo/dataflow-ir-consistency.expected

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,7 @@
11
uniqueEnclosingCallable
22
uniqueType
33
uniqueNodeLocation
4-
| file://:0:0:0:0 | (unnamed parameter 2) | Node should have one location but has 0. |
5-
| file://:0:0:0:0 | (unnamed parameter 2) | Node should have one location but has 0. |
6-
| file://:0:0:0:0 | (unnamed parameter 2) | Node should have one location but has 0. |
7-
| file://:0:0:0:0 | (unnamed parameter 2) | Node should have one location but has 0. |
8-
| file://:0:0:0:0 | (unnamed parameter 2) | Node should have one location but has 0. |
9-
| file://:0:0:0:0 | (unnamed parameter 2) indirection | Node should have one location but has 0. |
10-
| file://:0:0:0:0 | (unnamed parameter 2) indirection | Node should have one location but has 0. |
11-
| file://:0:0:0:0 | (unnamed parameter 2) indirection | Node should have one location but has 0. |
12-
| file://:0:0:0:0 | (unnamed parameter 2) indirection | Node should have one location but has 0. |
13-
| file://:0:0:0:0 | (unnamed parameter 2) indirection | Node should have one location but has 0. |
14-
| file://:0:0:0:0 | (unnamed parameter 2) indirection | Node should have one location but has 0. |
15-
| file://:0:0:0:0 | (unnamed parameter 2) indirection | Node should have one location but has 0. |
164
missingLocation
17-
| Nodes without location: 12 |
185
uniqueNodeToString
196
missingToString
207
parameterCallable

0 commit comments

Comments
 (0)