Skip to content

Commit 50e182e

Browse files
committed
Hashcons definition of exprEq_propertyPermissive
1 parent f6f63cb commit 50e182e

2 files changed

Lines changed: 16 additions & 43 deletions

File tree

cpp/ql/src/Likely Bugs/Leap Year/LeapYear.qll

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import cpp
66
import semmle.code.cpp.dataflow.new.TaintTracking
77
import semmle.code.cpp.commons.DateTime
8+
import semmle.code.cpp.valuenumbering.HashCons
89

910
/**
1011
* Get the top-level `BinaryOperation` enclosing the expression e.
@@ -63,42 +64,11 @@ Expr moduloCheckNEQ_0(NEExpr neq, int modVal) {
6364
* Returns if the two expressions resolve to the same value, albeit it is a fuzzy attempt.
6465
* SSA is not fit for purpose here as calls break SSA equivalence.
6566
*/
67+
bindingset[e1,e2]
68+
pragma[inline_late]
6669
predicate exprEq_propertyPermissive(Expr e1, Expr e2) {
6770
not e1 = e2 and
68-
(
69-
DataFlow::localFlow(DataFlow::exprNode(e1), DataFlow::exprNode(e2))
70-
or
71-
if e1 instanceof ThisExpr and e2 instanceof ThisExpr
72-
then any()
73-
else
74-
/* If it's a direct Access, check that the target is the same. */
75-
if e1 instanceof Access
76-
then e1.(Access).getTarget() = e2.(Access).getTarget()
77-
else
78-
/* If it's a Call, compare qualifiers and only permit no-argument Calls. */
79-
if e1 instanceof Call
80-
then
81-
e1.(Call).getTarget() = e2.(Call).getTarget() and
82-
e1.(Call).getNumberOfArguments() = 0 and
83-
e2.(Call).getNumberOfArguments() = 0 and
84-
if e1.(Call).hasQualifier()
85-
then exprEq_propertyPermissive(e1.(Call).getQualifier(), e2.(Call).getQualifier())
86-
else any()
87-
else
88-
/* If it's a binaryOperation, compare op and recruse */
89-
if e1 instanceof BinaryOperation
90-
then
91-
e1.(BinaryOperation).getOperator() = e2.(BinaryOperation).getOperator() and
92-
exprEq_propertyPermissive(e1.(BinaryOperation).getLeftOperand(),
93-
e2.(BinaryOperation).getLeftOperand()) and
94-
exprEq_propertyPermissive(e1.(BinaryOperation).getRightOperand(),
95-
e2.(BinaryOperation).getRightOperand())
96-
else
97-
// Otherwise fail (and permit the raising of a finding)
98-
if e1 instanceof Literal
99-
then e1.(Literal).getValue() = e2.(Literal).getValue()
100-
else none()
101-
)
71+
hashCons(e1) = hashCons(e2)
10272
}
10373

10474
/**

cpp/ql/src/Likely Bugs/Leap Year/UncheckedLeapYearAfterYearModificationPrecise.ql

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,17 +138,20 @@ class YearFieldAssignmentUnary extends YearFieldAssignment instanceof CrementOpe
138138
override YearFieldAccess getYearFieldAccess() { result = access }
139139
}
140140

141+
// *
142+
// An access to either a Month or Day.
143+
// /
144+
// class MonthOrDayFieldAccess extends FieldAccess {
145+
// MonthOrDayFieldAccess() {
146+
// this instanceof MonthFieldAccess
147+
// or
148+
// this instanceof DayFieldAccess
149+
// }
150+
// }
151+
141152
/**
142-
* An access to either a Month or Day.
153+
* An operation of interest to source from
143154
*/
144-
class MonthOrDayFieldAccess extends FieldAccess {
145-
MonthOrDayFieldAccess() {
146-
this instanceof MonthFieldAccess
147-
or
148-
this instanceof DayFieldAccess
149-
}
150-
}
151-
152155
class OperationNode extends DataFlow::Node{
153156
OperationNode(){
154157
this.asExpr() instanceof Operation

0 commit comments

Comments
 (0)