Skip to content

Commit 3c83217

Browse files
committed
C++: Add new dataflow nodes for parameters without any Instructions associated with them.
1 parent 5891d42 commit 3c83217

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ module NodeStars {
7878
result = n.(PostUpdateNodeImpl).getIndirectionIndex()
7979
or
8080
result = n.(FinalParameterNode).getIndirectionIndex()
81+
or
82+
result = n.(BodyLessParameterNodeImpl).getIndirectionIndex()
8183
}
8284

8385
/**

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ private newtype TIRDataFlowNode =
6161
} or
6262
TFinalGlobalValue(Ssa::GlobalUse globalUse) or
6363
TInitialGlobalValue(Ssa::GlobalDef globalUse) or
64+
TBodyLessParameterNodeImpl(Parameter p, int indirectionIndex) {
65+
// We subtract one because `getMaxIndirectionsForType` returns the maximum
66+
// indirection for a glvalue of a given type, and this doesn't apply to
67+
// parameters.
68+
indirectionIndex = [0 .. Ssa::getMaxIndirectionsForType(p.getUnspecifiedType()) - 1] and
69+
not any(InitializeParameterInstruction init).getParameter() = p
70+
} or
6471
TFlowSummaryNode(FlowSummaryImpl::Private::SummaryNode sn)
6572

6673
/**
@@ -737,6 +744,39 @@ class InitialGlobalValue extends Node, TInitialGlobalValue {
737744
override string toStringImpl() { result = globalDef.toString() }
738745
}
739746

747+
/**
748+
* INTERNAL: do not use.
749+
*
750+
* A node representing a parameter for a function with no body.
751+
*/
752+
class BodyLessParameterNodeImpl extends Node, TBodyLessParameterNodeImpl {
753+
Parameter p;
754+
int indirectionIndex;
755+
756+
BodyLessParameterNodeImpl() { this = TBodyLessParameterNodeImpl(p, indirectionIndex) }
757+
758+
override Declaration getEnclosingCallable() { result = this.getFunction() }
759+
760+
override Declaration getFunction() { result = p.getFunction() }
761+
762+
int getIndirectionIndex() { result = indirectionIndex }
763+
764+
override DataFlowType getType() {
765+
result = getTypeImpl(p.getUnderlyingType(), this.getIndirectionIndex())
766+
}
767+
768+
final override Location getLocationImpl() {
769+
result = unique( | | p.getLocation())
770+
or
771+
count(p.getLocation()) != 1 and
772+
result instanceof UnknownDefaultLocation
773+
}
774+
775+
final override string toStringImpl() {
776+
exists(string prefix | prefix = stars(this) | result = prefix + p.toString())
777+
}
778+
}
779+
740780
/**
741781
* A data-flow node used to model flow summaries. That is, a dataflow node
742782
* that is synthesized to represent a parameter, return value, or other part

0 commit comments

Comments
 (0)