Skip to content

Commit a3a3423

Browse files
committed
C++: Treat reference parameters as non-references
1 parent 6eca97b commit a3a3423

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

cpp/ql/src/semmle/code/cpp/controlflow/SSAUtils.qll

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,20 @@ private predicate addressTakenVariable(StackVariable var) {
7373
)
7474
}
7575

76+
/**
77+
* Holds if `v` is a stack-allocated reference-typed local variable. We don't
78+
* build SSA for such variables since they are likely to change values even
79+
* when not syntactically mentioned. For the same reason,
80+
* `addressTakenVariable` is used to prevent tracking variables that may be
81+
* aliased by such a reference.
82+
*
83+
* Reference-typed parameters are treated as if they weren't references.
84+
* That's because it's in practice highly unlikely that they alias other data
85+
* accessible from the function body.
86+
*/
7687
private predicate isReferenceVar(StackVariable v) {
77-
v.getUnspecifiedType() instanceof ReferenceType
88+
v.getUnspecifiedType() instanceof ReferenceType and
89+
not v instanceof Parameter
7890
}
7991

8092
/**

0 commit comments

Comments
 (0)