Skip to content

Commit e620bfa

Browse files
authored
Merge pull request github#15761 from MathiasVP/fewer-variablenodes
C++: Restrict `VariableNode`s to only be global-like variables
2 parents 7beafc9 + 4474b54 commit e620bfa

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private import Node0ToString
3434
cached
3535
private newtype TIRDataFlowNode =
3636
TNode0(Node0Impl node) { DataFlowImplCommon::forceCachingInSameStage() } or
37-
TVariableNode(Variable var, int indirectionIndex) {
37+
TGlobalLikeVariableNode(GlobalLikeVariable var, int indirectionIndex) {
3838
indirectionIndex =
3939
[getMinIndirectionsForType(var.getUnspecifiedType()) .. Ssa::getMaxIndirectionsForType(var.getUnspecifiedType())]
4040
} or
@@ -396,7 +396,7 @@ class Node extends TIRDataFlowNode {
396396
* modeling flow in and out of global variables.
397397
*/
398398
Variable asVariable() {
399-
this = TVariableNode(result, getMinIndirectionsForType(result.getUnspecifiedType()))
399+
this = TGlobalLikeVariableNode(result, getMinIndirectionsForType(result.getUnspecifiedType()))
400400
}
401401

402402
/**
@@ -406,7 +406,7 @@ class Node extends TIRDataFlowNode {
406406
*/
407407
Variable asIndirectVariable(int indirectionIndex) {
408408
indirectionIndex > getMinIndirectionsForType(result.getUnspecifiedType()) and
409-
this = TVariableNode(result, indirectionIndex)
409+
this = TGlobalLikeVariableNode(result, indirectionIndex)
410410
}
411411

412412
/** Gets an indirection of this node's underlying variable, if any. */
@@ -1751,15 +1751,18 @@ class DefinitionByReferenceNode extends IndirectArgumentOutNode {
17511751
}
17521752

17531753
/**
1754-
* A `Node` corresponding to a variable in the program, as opposed to the
1755-
* value of that variable at some particular point. This can be used for
1756-
* modeling flow in and out of global variables.
1754+
* A `Node` corresponding to a global (or `static` local) variable in the
1755+
* program, as opposed to the value of that variable at some particular point.
1756+
* This is used to model flow through global variables (and `static` local
1757+
* variables).
1758+
*
1759+
* There is no `VariableNode` for non-`static` local variables.
17571760
*/
1758-
class VariableNode extends Node, TVariableNode {
1761+
class VariableNode extends Node, TGlobalLikeVariableNode {
17591762
Variable v;
17601763
int indirectionIndex;
17611764

1762-
VariableNode() { this = TVariableNode(v, indirectionIndex) }
1765+
VariableNode() { this = TGlobalLikeVariableNode(v, indirectionIndex) }
17631766

17641767
/** Gets the variable corresponding to this node. */
17651768
Variable getVariable() { result = v }

0 commit comments

Comments
 (0)