Skip to content

Commit 458ee13

Browse files
committed
C++: Add constant analysis for bitwise operations now that these are no longer constant folded by IR construction.
1 parent 54262a5 commit 458ee13

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

cpp/ql/lib/semmle/code/cpp/ir/implementation/raw/constant/ConstantAnalysis.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ private int getBinaryInstructionValue(BinaryInstruction instr) {
3838
or
3939
instr instanceof DivInstruction and result = div(left, right)
4040
or
41+
instr instanceof BitOrInstruction and result = bitOr(left, right)
42+
or
43+
instr instanceof BitAndInstruction and result = bitAnd(left, right)
44+
or
45+
instr instanceof BitXorInstruction and result = bitXor(left, right)
46+
or
4147
instr instanceof CompareEQInstruction and result = compareEQ(left, right)
4248
or
4349
instr instanceof CompareNEInstruction and result = compareNE(left, right)

cpp/ql/lib/semmle/code/cpp/ir/internal/IntegerPartial.qll

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ int compareLE(int a, int b) { if a <= b then result = 1 else result = 0 }
8989
bindingset[a, b]
9090
int compareGE(int a, int b) { if a >= b then result = 1 else result = 0 }
9191

92+
/** Returns `a >= b`. */
93+
bindingset[a, b]
94+
int bitOr(int a, int b) { result = a.bitOr(b) }
95+
96+
/** Returns `a >= b`. */
97+
bindingset[a, b]
98+
int bitAnd(int a, int b) { result = a.bitAnd(b) }
99+
100+
/** Returns `a >= b`. */
101+
bindingset[a, b]
102+
int bitXor(int a, int b) { result = a.bitXor(b) }
103+
92104
/**
93105
* Returns `-a`. If the negation would overflow, there is no result.
94106
*/

0 commit comments

Comments
 (0)