Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 026a13b

Browse files
committed
C++: Change Node/Node0.getEnclosingCallable back to returning Declaration.
1 parent 4bc272d commit 026a13b

4 files changed

Lines changed: 28 additions & 26 deletions

File tree

cpp/ql/lib/semmle/code/cpp/ir/dataflow/ResolveCall.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import cpp
77
private import semmle.code.cpp.ir.ValueNumbering
88
private import internal.DataFlowDispatch
99
private import semmle.code.cpp.ir.IR
10+
private import semmle.code.cpp.ir.dataflow.internal.DataFlowPrivate
1011

1112
/**
1213
* Resolve potential target function(s) for `call`.
@@ -16,8 +17,9 @@ private import semmle.code.cpp.ir.IR
1617
* to identify the possible target(s).
1718
*/
1819
Function resolveCall(Call call) {
19-
exists(CallInstruction callInstruction |
20+
exists(DataFlowCall dataFlowCall, CallInstruction callInstruction |
2021
callInstruction.getAst() = call and
21-
result = viableCallable(callInstruction)
22+
callInstruction = dataFlowCall.asCallInstruction() and
23+
result = viableCallable(dataFlowCall).getUnderlyingCallable()
2224
)
2325
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private module VirtualDispatch {
152152
ReturnNode node, ReturnKind kind, DataFlowCallable callable
153153
) {
154154
node.getKind() = kind and
155-
node.getEnclosingCallable() = callable
155+
node.getEnclosingCallable() = callable.getUnderlyingCallable()
156156
}
157157

158158
/** Call through a function pointer. */

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class Node0Impl extends TIRDataFlowNode0 {
107107
/**
108108
* INTERNAL: Do not use.
109109
*/
110-
DataFlowCallable getEnclosingCallable() { none() } // overridden in subclasses
110+
Declaration getEnclosingCallable() { none() } // overridden in subclasses
111111

112112
/** Gets the function to which this node belongs, if any. */
113113
Declaration getFunction() { none() } // overridden in subclasses
@@ -177,7 +177,7 @@ abstract class InstructionNode0 extends Node0Impl {
177177
/** Gets the instruction corresponding to this node. */
178178
Instruction getInstruction() { result = instr }
179179

180-
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
180+
override Declaration getEnclosingCallable() { result = this.getFunction() }
181181

182182
override Declaration getFunction() { result = instr.getEnclosingFunction() }
183183

@@ -222,7 +222,7 @@ abstract class OperandNode0 extends Node0Impl {
222222
/** Gets the operand corresponding to this node. */
223223
Operand getOperand() { result = op }
224224

225-
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
225+
override Declaration getEnclosingCallable() { result = this.getFunction() }
226226

227227
override Declaration getFunction() { result = op.getUse().getEnclosingFunction() }
228228

@@ -339,7 +339,7 @@ private module IndirectInstructions {
339339
import IndirectInstructions
340340

341341
/** Gets the callable in which this node occurs. */
342-
DataFlowCallable nodeGetEnclosingCallable(Node n) { result = n.getEnclosingCallable() }
342+
DataFlowCallable nodeGetEnclosingCallable(Node n) { result.asSourceCallable() = n.getEnclosingCallable() }
343343

344344
/** Holds if `p` is a `ParameterNode` of `c` with position `pos`. */
345345
predicate isParameterNode(ParameterNode p, DataFlowCallable c, ParameterPosition pos) {

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

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class Node extends TIRDataFlowNode {
126126
/**
127127
* INTERNAL: Do not use.
128128
*/
129-
DataFlowCallable getEnclosingCallable() { none() } // overridden in subclasses
129+
Declaration getEnclosingCallable() { none() } // overridden in subclasses
130130

131131
/** Gets the function to which this node belongs, if any. */
132132
Declaration getFunction() { none() } // overridden in subclasses
@@ -479,7 +479,7 @@ private class Node0 extends Node, TNode0 {
479479

480480
Node0() { this = TNode0(node) }
481481

482-
override DataFlowCallable getEnclosingCallable() { result = node.getEnclosingCallable() }
482+
override Declaration getEnclosingCallable() { result = node.getEnclosingCallable() }
483483

484484
override Declaration getFunction() { result = node.getFunction() }
485485

@@ -544,7 +544,7 @@ class PostUpdateNodeImpl extends PartialDefinitionNode, TPostUpdateNodeImpl {
544544

545545
override Declaration getFunction() { result = operand.getUse().getEnclosingFunction() }
546546

547-
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
547+
override Declaration getEnclosingCallable() { result = this.getFunction() }
548548

549549
/** Gets the operand associated with this node. */
550550
Operand getOperand() { result = operand }
@@ -597,7 +597,7 @@ class SsaPhiNode extends Node, TSsaPhiNode {
597597
/** Gets the phi node associated with this node. */
598598
Ssa::PhiNode getPhiNode() { result = phi }
599599

600-
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
600+
override Declaration getEnclosingCallable() { result = this.getFunction() }
601601

602602
override Declaration getFunction() { result = phi.getBasicBlock().getEnclosingFunction() }
603603

@@ -666,7 +666,7 @@ class SideEffectOperandNode extends Node instanceof IndirectOperand {
666666

667667
int getArgumentIndex() { result = argumentIndex }
668668

669-
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
669+
override Declaration getEnclosingCallable() { result = this.getFunction() }
670670

671671
override Declaration getFunction() { result = call.getEnclosingFunction() }
672672

@@ -687,7 +687,7 @@ class FinalGlobalValue extends Node, TFinalGlobalValue {
687687
/** Gets the underlying SSA use. */
688688
Ssa::GlobalUse getGlobalUse() { result = globalUse }
689689

690-
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
690+
override Declaration getEnclosingCallable() { result = this.getFunction() }
691691

692692
override Declaration getFunction() { result = globalUse.getIRFunction().getFunction() }
693693

@@ -717,7 +717,7 @@ class InitialGlobalValue extends Node, TInitialGlobalValue {
717717
/** Gets the underlying SSA definition. */
718718
Ssa::GlobalDef getGlobalDef() { result = globalDef }
719719

720-
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
720+
override Declaration getEnclosingCallable() { result = this.getFunction() }
721721

722722
override Declaration getFunction() { result = globalDef.getIRFunction().getFunction() }
723723

@@ -756,8 +756,8 @@ class FlowSummaryNode extends Node, TFlowSummaryNode {
756756
/**
757757
* TODO: QLDoc.
758758
*/
759-
override DataFlowCallable getEnclosingCallable() {
760-
result = TSummarizedCallable(this.getSummarizedCallable()) // TODO: this doesn't look right.
759+
override Declaration getEnclosingCallable() {
760+
result = this.getSummarizedCallable() // TODO: this doesn't look right.
761761
}
762762

763763
override Location getLocationImpl() { result = this.getSummarizedCallable().getLocation() }
@@ -780,7 +780,7 @@ class IndirectParameterNode extends Node instanceof IndirectInstruction {
780780
/** Gets the parameter whose indirection is initialized. */
781781
Parameter getParameter() { result = init.getParameter() }
782782

783-
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
783+
override Declaration getEnclosingCallable() { result = this.getFunction() }
784784

785785
override Declaration getFunction() { result = init.getEnclosingFunction() }
786786

@@ -815,7 +815,7 @@ class IndirectReturnNode extends Node {
815815
.hasOperandAndIndirectionIndex(any(ReturnValueInstruction ret).getReturnAddressOperand(), _)
816816
}
817817

818-
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
818+
override Declaration getEnclosingCallable() { result = this.getFunction() }
819819

820820
/**
821821
* Holds if this node represents the value that is returned to the caller
@@ -1013,8 +1013,8 @@ private module RawIndirectNodes {
10131013
result = this.getOperand().getDef().getEnclosingFunction()
10141014
}
10151015

1016-
override DataFlowCallable getEnclosingCallable() {
1017-
result = TSourceCallable(this.getFunction())
1016+
override Declaration getEnclosingCallable() {
1017+
result = this.getFunction()
10181018
}
10191019

10201020
override predicate isGLValue() { this.getOperand().isGLValue() }
@@ -1059,8 +1059,8 @@ private module RawIndirectNodes {
10591059

10601060
override Declaration getFunction() { result = this.getInstruction().getEnclosingFunction() }
10611061

1062-
override DataFlowCallable getEnclosingCallable() {
1063-
result = TSourceCallable(this.getFunction())
1062+
override Declaration getEnclosingCallable() {
1063+
result = this.getFunction()
10641064
}
10651065

10661066
override predicate isGLValue() { this.getInstruction().isGLValue() }
@@ -1161,7 +1161,7 @@ class FinalParameterNode extends Node, TFinalParameterNode {
11611161

11621162
override Declaration getFunction() { result = p.getFunction() }
11631163

1164-
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
1164+
override Declaration getEnclosingCallable() { result = this.getFunction() }
11651165

11661166
override DataFlowType getType() { result = getTypeImpl(p.getUnderlyingType(), indirectionIndex) }
11671167

@@ -1737,7 +1737,7 @@ private predicate indirectParameterNodeHasArgumentIndexAndIndex(
17371737
/** A synthetic parameter to model the pointed-to object of a pointer parameter. */
17381738
class ParameterIndirectionNode extends ParameterNode instanceof IndirectParameterNode {
17391739
override predicate isParameterOf(DataFlowCallable f, ParameterPosition pos) {
1740-
IndirectParameterNode.super.getEnclosingCallable() = f and
1740+
IndirectParameterNode.super.getEnclosingCallable() = f.getUnderlyingCallable() and
17411741
exists(int argumentIndex, int indirectionIndex |
17421742
indirectPositionHasArgumentIndexAndIndex(pos, argumentIndex, indirectionIndex) and
17431743
indirectParameterNodeHasArgumentIndexAndIndex(this, argumentIndex, indirectionIndex)
@@ -1842,13 +1842,13 @@ class VariableNode extends Node, TVariableNode {
18421842

18431843
override Declaration getFunction() { none() }
18441844

1845-
override DataFlowCallable getEnclosingCallable() {
1845+
override Declaration getEnclosingCallable() {
18461846
// When flow crosses from one _enclosing callable_ to another, the
18471847
// interprocedural data-flow library discards call contexts and inserts a
18481848
// node in the big-step relation used for human-readable path explanations.
18491849
// Therefore we want a distinct enclosing callable for each `VariableNode`,
18501850
// and that can be the `Variable` itself.
1851-
result = TSourceCallable(v)
1851+
result = v
18521852
}
18531853

18541854
override DataFlowType getType() {

0 commit comments

Comments
 (0)