C++: Change Node/Node0.getEnclosingCallable back to returning Declaration.

This commit is contained in:
Geoffrey White
2024-03-11 12:12:01 +00:00
parent 4bc272da73
commit 026a13b4db
4 changed files with 28 additions and 26 deletions

View File

@@ -7,6 +7,7 @@ import cpp
private import semmle.code.cpp.ir.ValueNumbering
private import internal.DataFlowDispatch
private import semmle.code.cpp.ir.IR
private import semmle.code.cpp.ir.dataflow.internal.DataFlowPrivate
/**
* Resolve potential target function(s) for `call`.
@@ -16,8 +17,9 @@ private import semmle.code.cpp.ir.IR
* to identify the possible target(s).
*/
Function resolveCall(Call call) {
exists(CallInstruction callInstruction |
exists(DataFlowCall dataFlowCall, CallInstruction callInstruction |
callInstruction.getAst() = call and
result = viableCallable(callInstruction)
callInstruction = dataFlowCall.asCallInstruction() and
result = viableCallable(dataFlowCall).getUnderlyingCallable()
)
}

View File

@@ -152,7 +152,7 @@ private module VirtualDispatch {
ReturnNode node, ReturnKind kind, DataFlowCallable callable
) {
node.getKind() = kind and
node.getEnclosingCallable() = callable
node.getEnclosingCallable() = callable.getUnderlyingCallable()
}
/** Call through a function pointer. */

View File

@@ -107,7 +107,7 @@ class Node0Impl extends TIRDataFlowNode0 {
/**
* INTERNAL: Do not use.
*/
DataFlowCallable getEnclosingCallable() { none() } // overridden in subclasses
Declaration getEnclosingCallable() { none() } // overridden in subclasses
/** Gets the function to which this node belongs, if any. */
Declaration getFunction() { none() } // overridden in subclasses
@@ -177,7 +177,7 @@ abstract class InstructionNode0 extends Node0Impl {
/** Gets the instruction corresponding to this node. */
Instruction getInstruction() { result = instr }
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
override Declaration getEnclosingCallable() { result = this.getFunction() }
override Declaration getFunction() { result = instr.getEnclosingFunction() }
@@ -222,7 +222,7 @@ abstract class OperandNode0 extends Node0Impl {
/** Gets the operand corresponding to this node. */
Operand getOperand() { result = op }
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
override Declaration getEnclosingCallable() { result = this.getFunction() }
override Declaration getFunction() { result = op.getUse().getEnclosingFunction() }
@@ -339,7 +339,7 @@ private module IndirectInstructions {
import IndirectInstructions
/** Gets the callable in which this node occurs. */
DataFlowCallable nodeGetEnclosingCallable(Node n) { result = n.getEnclosingCallable() }
DataFlowCallable nodeGetEnclosingCallable(Node n) { result.asSourceCallable() = n.getEnclosingCallable() }
/** Holds if `p` is a `ParameterNode` of `c` with position `pos`. */
predicate isParameterNode(ParameterNode p, DataFlowCallable c, ParameterPosition pos) {

View File

@@ -126,7 +126,7 @@ class Node extends TIRDataFlowNode {
/**
* INTERNAL: Do not use.
*/
DataFlowCallable getEnclosingCallable() { none() } // overridden in subclasses
Declaration getEnclosingCallable() { none() } // overridden in subclasses
/** Gets the function to which this node belongs, if any. */
Declaration getFunction() { none() } // overridden in subclasses
@@ -479,7 +479,7 @@ private class Node0 extends Node, TNode0 {
Node0() { this = TNode0(node) }
override DataFlowCallable getEnclosingCallable() { result = node.getEnclosingCallable() }
override Declaration getEnclosingCallable() { result = node.getEnclosingCallable() }
override Declaration getFunction() { result = node.getFunction() }
@@ -544,7 +544,7 @@ class PostUpdateNodeImpl extends PartialDefinitionNode, TPostUpdateNodeImpl {
override Declaration getFunction() { result = operand.getUse().getEnclosingFunction() }
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
override Declaration getEnclosingCallable() { result = this.getFunction() }
/** Gets the operand associated with this node. */
Operand getOperand() { result = operand }
@@ -597,7 +597,7 @@ class SsaPhiNode extends Node, TSsaPhiNode {
/** Gets the phi node associated with this node. */
Ssa::PhiNode getPhiNode() { result = phi }
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
override Declaration getEnclosingCallable() { result = this.getFunction() }
override Declaration getFunction() { result = phi.getBasicBlock().getEnclosingFunction() }
@@ -666,7 +666,7 @@ class SideEffectOperandNode extends Node instanceof IndirectOperand {
int getArgumentIndex() { result = argumentIndex }
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
override Declaration getEnclosingCallable() { result = this.getFunction() }
override Declaration getFunction() { result = call.getEnclosingFunction() }
@@ -687,7 +687,7 @@ class FinalGlobalValue extends Node, TFinalGlobalValue {
/** Gets the underlying SSA use. */
Ssa::GlobalUse getGlobalUse() { result = globalUse }
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
override Declaration getEnclosingCallable() { result = this.getFunction() }
override Declaration getFunction() { result = globalUse.getIRFunction().getFunction() }
@@ -717,7 +717,7 @@ class InitialGlobalValue extends Node, TInitialGlobalValue {
/** Gets the underlying SSA definition. */
Ssa::GlobalDef getGlobalDef() { result = globalDef }
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
override Declaration getEnclosingCallable() { result = this.getFunction() }
override Declaration getFunction() { result = globalDef.getIRFunction().getFunction() }
@@ -756,8 +756,8 @@ class FlowSummaryNode extends Node, TFlowSummaryNode {
/**
* TODO: QLDoc.
*/
override DataFlowCallable getEnclosingCallable() {
result = TSummarizedCallable(this.getSummarizedCallable()) // TODO: this doesn't look right.
override Declaration getEnclosingCallable() {
result = this.getSummarizedCallable() // TODO: this doesn't look right.
}
override Location getLocationImpl() { result = this.getSummarizedCallable().getLocation() }
@@ -780,7 +780,7 @@ class IndirectParameterNode extends Node instanceof IndirectInstruction {
/** Gets the parameter whose indirection is initialized. */
Parameter getParameter() { result = init.getParameter() }
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
override Declaration getEnclosingCallable() { result = this.getFunction() }
override Declaration getFunction() { result = init.getEnclosingFunction() }
@@ -815,7 +815,7 @@ class IndirectReturnNode extends Node {
.hasOperandAndIndirectionIndex(any(ReturnValueInstruction ret).getReturnAddressOperand(), _)
}
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
override Declaration getEnclosingCallable() { result = this.getFunction() }
/**
* Holds if this node represents the value that is returned to the caller
@@ -1013,8 +1013,8 @@ private module RawIndirectNodes {
result = this.getOperand().getDef().getEnclosingFunction()
}
override DataFlowCallable getEnclosingCallable() {
result = TSourceCallable(this.getFunction())
override Declaration getEnclosingCallable() {
result = this.getFunction()
}
override predicate isGLValue() { this.getOperand().isGLValue() }
@@ -1059,8 +1059,8 @@ private module RawIndirectNodes {
override Declaration getFunction() { result = this.getInstruction().getEnclosingFunction() }
override DataFlowCallable getEnclosingCallable() {
result = TSourceCallable(this.getFunction())
override Declaration getEnclosingCallable() {
result = this.getFunction()
}
override predicate isGLValue() { this.getInstruction().isGLValue() }
@@ -1161,7 +1161,7 @@ class FinalParameterNode extends Node, TFinalParameterNode {
override Declaration getFunction() { result = p.getFunction() }
override DataFlowCallable getEnclosingCallable() { result = TSourceCallable(this.getFunction()) }
override Declaration getEnclosingCallable() { result = this.getFunction() }
override DataFlowType getType() { result = getTypeImpl(p.getUnderlyingType(), indirectionIndex) }
@@ -1737,7 +1737,7 @@ private predicate indirectParameterNodeHasArgumentIndexAndIndex(
/** A synthetic parameter to model the pointed-to object of a pointer parameter. */
class ParameterIndirectionNode extends ParameterNode instanceof IndirectParameterNode {
override predicate isParameterOf(DataFlowCallable f, ParameterPosition pos) {
IndirectParameterNode.super.getEnclosingCallable() = f and
IndirectParameterNode.super.getEnclosingCallable() = f.getUnderlyingCallable() and
exists(int argumentIndex, int indirectionIndex |
indirectPositionHasArgumentIndexAndIndex(pos, argumentIndex, indirectionIndex) and
indirectParameterNodeHasArgumentIndexAndIndex(this, argumentIndex, indirectionIndex)
@@ -1842,13 +1842,13 @@ class VariableNode extends Node, TVariableNode {
override Declaration getFunction() { none() }
override DataFlowCallable getEnclosingCallable() {
override Declaration getEnclosingCallable() {
// When flow crosses from one _enclosing callable_ to another, the
// interprocedural data-flow library discards call contexts and inserts a
// node in the big-step relation used for human-readable path explanations.
// Therefore we want a distinct enclosing callable for each `VariableNode`,
// and that can be the `Variable` itself.
result = TSourceCallable(v)
result = v
}
override DataFlowType getType() {