Skip to content

Commit 77c5a8e

Browse files
author
Robert Marsh
committed
C++: support impure binary operations in HashCons
1 parent b8bd285 commit 77c5a8e

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

cpp/ql/src/semmle/code/cpp/valuenumbering/HashCons.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ private predicate mk_Conversion(Type t, HC child, Conversion conv) {
288288
}
289289

290290
private predicate analyzableBinaryOp(BinaryOperation op) {
291-
op.isPure() and
292291
strictcount (op.getLeftOperand().getFullyConverted()) = 1 and
293292
strictcount (op.getRightOperand().getFullyConverted()) = 1 and
294293
strictcount (op.getOperator()) = 1

cpp/ql/test/library-tests/valuenumbering/HashCons/HashCons.expected

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,6 @@
6363
| test.cpp:141:12:141:17 | call to getInt | 141:c12-c17 141:c29-c34 |
6464
| test.cpp:146:10:146:11 | ih | 146:c10-c11 146:c31-c32 |
6565
| test.cpp:146:13:146:25 | call to getDoubledInt | 146:c13-c25 146:c34-c46 |
66+
| test.cpp:150:3:150:3 | x | 150:c3-c3 150:c9-c9 151:c3-c3 151:c9-c9 152:c12-c12 |
67+
| test.cpp:150:3:150:5 | ... ++ | 150:c3-c5 150:c9-c11 151:c3-c5 151:c9-c11 152:c10-c12 |
68+
| test.cpp:150:3:150:11 | ... + ... | 150:c3-c11 151:c3-c11 |

cpp/ql/test/library-tests/valuenumbering/HashCons/test.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,16 @@ class IntHolder {
138138

139139
public:
140140
int getDoubledInt() {
141-
return getInt() + this->getInt();
141+
return getInt() + this->getInt(); // getInt() and this->getInt() should be the same
142142
}
143143
};
144144

145-
int quadrupleInt(IntHolder ih) {
145+
int test09(IntHolder ih) {
146146
return ih.getDoubledInt() + ih.getDoubledInt();
147147
}
148+
149+
int test10(int x) {
150+
x++ + x++;
151+
x++ + x++; // same as above
152+
return ++x; // ++x is not the same as x++
153+
}

0 commit comments

Comments
 (0)