Skip to content

Commit 86dbb50

Browse files
committed
C++: Add more comments to explain the meaning of 'combineWith'.
1 parent 75c3332 commit 86dbb50

File tree

1 file changed

+8
-0
lines changed
  • cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis

1 file changed

+8
-0
lines changed

cpp/ql/lib/semmle/code/cpp/rangeanalysis/new/internal/semantic/analysis/Reason.qll

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ module Make<ParamSig Param> {
5454

5555
bindingset[this, reason]
5656
override SemReason combineWith(SemReason reason) {
57+
// Since we end up reporting a `SemReason` for the inferred bound we often pick somewhat
58+
// arbitrarily between two `SemReason`s during the analysis. This isn't an issue for most reasons
59+
// since they're mainly used for constructing alert messages. However, the `SemTypeReason` is
60+
// supposed to be used in query logic to filter out bounds inferred by type-based analysis if
61+
// the query author chooses to do so. So we need to ensure that if _any_ of the bounds that
62+
// contribute to the final bound depends on type information then the `SemReason` we report must
63+
// be a `SemTypeReason`. So when we need to combine this `SemCondReason` with a `SemTypeReason`
64+
// the result should always be a `SemTypeReason`.
5765
if reason instanceof SemTypeReason then result instanceof SemTypeReason else result = this
5866
}
5967
}

0 commit comments

Comments
 (0)