mirror of
https://github.com/github/codeql.git
synced 2026-04-22 07:15:15 +02:00
C++: Cleanup.
This commit is contained in:
@@ -763,11 +763,7 @@ private predicate compares_eq(
|
||||
compares_eq(test.(LogicalNotInstruction).getUnary(), left, right, k, areEqual, dual)
|
||||
)
|
||||
or
|
||||
exists(CallInstruction call |
|
||||
test = call and
|
||||
call.getStaticCallTarget().hasName("__builtin_expect") and
|
||||
compares_eq(call.getArgument(0).(ConvertInstruction).getUnary(), left, right, k, areEqual, value)
|
||||
)
|
||||
compares_eq(test.(BuiltinExpectCallInstruction).getCondition(), left, right, k, areEqual, value)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -838,12 +834,8 @@ private predicate unary_compares_eq(
|
||||
k = k1 + k2
|
||||
)
|
||||
or
|
||||
exists(CallInstruction call, Instruction arg |
|
||||
test = call and
|
||||
call.getStaticCallTarget().hasName("__builtin_expect") and
|
||||
arg = call.getArgument(0) and
|
||||
unary_compares_eq(arg.(ConvertInstruction).getUnary(), op, k, areEqual, inNonZeroCase, value)
|
||||
)
|
||||
unary_compares_eq(test.(BuiltinExpectCallInstruction).getCondition(), op, k, areEqual,
|
||||
inNonZeroCase, value)
|
||||
}
|
||||
|
||||
/** Rearrange various simple comparisons into `left == right + k` form. */
|
||||
@@ -926,6 +918,13 @@ private predicate unary_simple_comparison_eq(
|
||||
/** A call to the builtin operation `__builtin_expect`. */
|
||||
private class BuiltinExpectCallInstruction extends CallInstruction {
|
||||
BuiltinExpectCallInstruction() { this.getStaticCallTarget().hasName("__builtin_expect") }
|
||||
|
||||
/** Gets the condition of this call. */
|
||||
Instruction getCondition() {
|
||||
// The first parameter of `__builtin_expect` has type `long`. So we skip
|
||||
// the conversion when inferring guards.
|
||||
result = this.getArgument(0).(ConvertInstruction).getUnary()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -935,14 +934,10 @@ private class BuiltinExpectCallInstruction extends CallInstruction {
|
||||
private predicate builtin_expect_eq(
|
||||
CompareInstruction cmp, Operand left, Operand right, int k, boolean areEqual, AbstractValue value
|
||||
) {
|
||||
exists(
|
||||
BuiltinExpectCallInstruction call, ConvertInstruction arg, Instruction const,
|
||||
AbstractValue innerValue
|
||||
|
|
||||
exists(BuiltinExpectCallInstruction call, Instruction const, AbstractValue innerValue |
|
||||
int_value(const) = 0 and
|
||||
cmp.hasOperands(call.getAUse(), const.getAUse()) and
|
||||
arg = call.getArgument(0) and
|
||||
compares_eq(arg.getUnary(), left, right, k, areEqual, innerValue)
|
||||
compares_eq(call.getCondition(), left, right, k, areEqual, innerValue)
|
||||
|
|
||||
cmp instanceof CompareNEInstruction and
|
||||
value = innerValue
|
||||
@@ -970,14 +965,10 @@ private predicate unary_builtin_expect_eq(
|
||||
CompareInstruction cmp, Operand op, int k, boolean areEqual, boolean inNonZeroCase,
|
||||
AbstractValue value
|
||||
) {
|
||||
exists(
|
||||
BuiltinExpectCallInstruction call, ConvertInstruction arg, Instruction const,
|
||||
AbstractValue innerValue
|
||||
|
|
||||
exists(BuiltinExpectCallInstruction call, Instruction const, AbstractValue innerValue |
|
||||
int_value(const) = 0 and
|
||||
cmp.hasOperands(call.getAUse(), const.getAUse()) and
|
||||
arg = call.getArgument(0) and
|
||||
unary_compares_eq(arg.getUnary(), op, k, areEqual, inNonZeroCase, innerValue)
|
||||
unary_compares_eq(call.getCondition(), op, k, areEqual, inNonZeroCase, innerValue)
|
||||
|
|
||||
cmp instanceof CompareNEInstruction and
|
||||
value = innerValue
|
||||
|
||||
Reference in New Issue
Block a user