mirror of
https://github.com/github/codeql.git
synced 2026-03-06 07:36:47 +01:00
Remove redundant "_ir" suffix. Move non-user-importable modules into "implementation" directory.
31 lines
1.2 KiB
Plaintext
31 lines
1.2 KiB
Plaintext
import default
|
|
import semmle.code.cpp.ir.IR
|
|
import semmle.code.cpp.ir.internal.IntegerConstant
|
|
|
|
language[monotonicAggregates]
|
|
IntValue getConstantValue(Instruction instr) {
|
|
result = instr.(IntegerConstantInstruction).getValue().toInt() or
|
|
exists(BinaryInstruction binInstr, IntValue left, IntValue right |
|
|
binInstr = instr and
|
|
left = getConstantValue(binInstr.getLeftOperand()) and
|
|
right = getConstantValue(binInstr.getRightOperand()) and
|
|
(
|
|
binInstr instanceof AddInstruction and result = add(left, right) or
|
|
binInstr instanceof SubInstruction and result = sub(left, right) or
|
|
binInstr instanceof MulInstruction and result = mul(left, right) or
|
|
binInstr instanceof DivInstruction and result = div(left, right)
|
|
)
|
|
) or
|
|
result = getConstantValue(instr.(CopyInstruction).getSourceValue()) or
|
|
exists(PhiInstruction phi |
|
|
phi = instr and
|
|
result = max(Instruction operand | operand = phi.getAnOperand() | getConstantValue(operand)) and
|
|
result = min(Instruction operand | operand = phi.getAnOperand() | getConstantValue(operand))
|
|
)
|
|
}
|
|
|
|
from FunctionIR funcIR, int value
|
|
where
|
|
value = getValue(getConstantValue(funcIR.getReturnInstruction().(ReturnValueInstruction).getReturnValue()))
|
|
select funcIR, value
|