diff --git a/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll b/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll index 1aafe6ff138..ea7bf69cc10 100644 --- a/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll +++ b/cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DataFlowUtil.qll @@ -405,7 +405,11 @@ class InstructionNode extends Node0 { /** Gets the instruction corresponding to this node. */ Instruction getInstruction() { result = instr } - override Location getLocationImpl() { result = instr.getAst().getLocation() } + override Location getLocationImpl() { + if exists(instr.getAst().getLocation()) + then result = instr.getAst().getLocation() + else result instanceof UnknownDefaultLocation + } override string toStringImpl() { if instr.(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable @@ -426,7 +430,11 @@ class OperandNode extends Node, Node0 { /** Gets the operand corresponding to this node. */ Operand getOperand() { result = op } - override Location getLocationImpl() { result = op.getDef().getAst().getLocation() } + override Location getLocationImpl() { + if exists(op.getDef().getAst().getLocation()) + then result = op.getDef().getAst().getLocation() + else result instanceof UnknownDefaultLocation + } override string toStringImpl() { if op.getDef().(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable @@ -641,6 +649,8 @@ class IndirectParameterNode extends Node, IndirectInstruction { override Declaration getFunction() { result = this.getInstruction().getEnclosingFunction() } + override Location getLocationImpl() { result = this.getParameter().getLocation() } + override string toStringImpl() { result = this.getParameter().toString() + " indirection" or @@ -888,7 +898,11 @@ class RawIndirectOperand extends Node, TRawIndirectOperand { ) } - final override Location getLocationImpl() { result = this.getOperand().getLocation() } + final override Location getLocationImpl() { + if exists(this.getOperand().getLocation()) + then result = this.getOperand().getLocation() + else result instanceof UnknownDefaultLocation + } override string toStringImpl() { result = instructionNode(this.getOperand().getDef()).toStringImpl() + " indirection" @@ -987,7 +1001,11 @@ class RawIndirectInstruction extends Node, TRawIndirectInstruction { ) } - final override Location getLocationImpl() { result = this.getInstruction().getLocation() } + final override Location getLocationImpl() { + if exists(this.getInstruction().getLocation()) + then result = this.getInstruction().getLocation() + else result instanceof UnknownDefaultLocation + } override string toStringImpl() { result = instructionNode(this.getInstruction()).toStringImpl() + " indirection" diff --git a/cpp/ql/test/library-tests/syntax-zoo/dataflow-ir-consistency.expected b/cpp/ql/test/library-tests/syntax-zoo/dataflow-ir-consistency.expected index 59353338b32..061778f9cb4 100644 --- a/cpp/ql/test/library-tests/syntax-zoo/dataflow-ir-consistency.expected +++ b/cpp/ql/test/library-tests/syntax-zoo/dataflow-ir-consistency.expected @@ -1,20 +1,7 @@ uniqueEnclosingCallable uniqueType uniqueNodeLocation -| file://:0:0:0:0 | (unnamed parameter 2) | Node should have one location but has 0. | -| file://:0:0:0:0 | (unnamed parameter 2) | Node should have one location but has 0. | -| file://:0:0:0:0 | (unnamed parameter 2) | Node should have one location but has 0. | -| file://:0:0:0:0 | (unnamed parameter 2) | Node should have one location but has 0. | -| file://:0:0:0:0 | (unnamed parameter 2) | Node should have one location but has 0. | -| file://:0:0:0:0 | (unnamed parameter 2) indirection | Node should have one location but has 0. | -| file://:0:0:0:0 | (unnamed parameter 2) indirection | Node should have one location but has 0. | -| file://:0:0:0:0 | (unnamed parameter 2) indirection | Node should have one location but has 0. | -| file://:0:0:0:0 | (unnamed parameter 2) indirection | Node should have one location but has 0. | -| file://:0:0:0:0 | (unnamed parameter 2) indirection | Node should have one location but has 0. | -| file://:0:0:0:0 | (unnamed parameter 2) indirection | Node should have one location but has 0. | -| file://:0:0:0:0 | (unnamed parameter 2) indirection | Node should have one location but has 0. | missingLocation -| Nodes without location: 12 | uniqueNodeToString missingToString parameterCallable