Skip to content

Commit 398b90a

Browse files
committed
C++: Rename a few predicates.
1 parent c483a4b commit 398b90a

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

cpp/ql/lib/semmle/code/cpp/controlflow/IRGuards.qll

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ class IRGuardCondition extends Instruction {
565565
/** Holds if (determined by this guard) `op == k` evaluates to `areEqual` if this expression evaluates to `value`. */
566566
cached
567567
predicate comparesEq(Operand op, int k, boolean areEqual, AbstractValue value) {
568-
compares_eq(this, op, k, areEqual, value)
568+
unary_compares_eq(this, op, k, areEqual, value)
569569
}
570570

571571
/**
@@ -586,7 +586,7 @@ class IRGuardCondition extends Instruction {
586586
cached
587587
predicate ensuresEq(Operand op, int k, IRBlock block, boolean areEqual) {
588588
exists(AbstractValue value |
589-
compares_eq(this, op, k, areEqual, value) and this.valueControls(block, value)
589+
unary_compares_eq(this, op, k, areEqual, value) and this.valueControls(block, value)
590590
)
591591
}
592592

@@ -611,7 +611,7 @@ class IRGuardCondition extends Instruction {
611611
cached
612612
predicate ensuresEqEdge(Operand op, int k, IRBlock pred, IRBlock succ, boolean areEqual) {
613613
exists(AbstractValue value |
614-
compares_eq(this, op, k, areEqual, value) and
614+
unary_compares_eq(this, op, k, areEqual, value) and
615615
this.valueControlsEdge(pred, succ, value)
616616
)
617617
}
@@ -738,21 +738,21 @@ private predicate compares_eq(
738738
}
739739

740740
/** Holds if `op == k` is `areEqual` given that `test` is equal to `value`. */
741-
private predicate compares_eq(
741+
private predicate unary_compares_eq(
742742
Instruction test, Operand op, int k, boolean areEqual, AbstractValue value
743743
) {
744744
/* The simple case where the test *is* the comparison so areEqual = testIsTrue xor eq. */
745-
exists(AbstractValue v | simple_comparison_eq(test, op, k, v) |
745+
exists(AbstractValue v | unary_simple_comparison_eq(test, op, k, v) |
746746
areEqual = true and value = v
747747
or
748748
areEqual = false and value = v.getDualValue()
749749
)
750750
or
751-
complex_eq(test, op, k, areEqual, value)
751+
unary_complex_eq(test, op, k, areEqual, value)
752752
or
753753
/* (x is true => (op == k)) => (!x is false => (op == k)) */
754754
exists(AbstractValue dual | value = dual.getDualValue() |
755-
compares_eq(test.(LogicalNotInstruction).getUnary(), op, k, areEqual, dual)
755+
unary_compares_eq(test.(LogicalNotInstruction).getUnary(), op, k, areEqual, dual)
756756
)
757757
or
758758
// ((test is `areEqual` => op == const + k2) and const == `k1`) =>
@@ -782,7 +782,9 @@ private predicate simple_comparison_eq(
782782
}
783783

784784
/** Rearrange various simple comparisons into `op == k` form. */
785-
private predicate simple_comparison_eq(Instruction test, Operand op, int k, AbstractValue value) {
785+
private predicate unary_simple_comparison_eq(
786+
Instruction test, Operand op, int k, AbstractValue value
787+
) {
786788
exists(SwitchInstruction switch, CaseEdge case |
787789
test = switch.getExpression() and
788790
op.getDef() = test and
@@ -821,12 +823,12 @@ private predicate complex_eq(
821823
add_eq(cmp, left, right, k, areEqual, value)
822824
}
823825

824-
private predicate complex_eq(
826+
private predicate unary_complex_eq(
825827
Instruction test, Operand op, int k, boolean areEqual, AbstractValue value
826828
) {
827-
sub_eq(test, op, k, areEqual, value)
829+
unary_sub_eq(test, op, k, areEqual, value)
828830
or
829-
add_eq(test, op, k, areEqual, value)
831+
unary_add_eq(test, op, k, areEqual, value)
830832
}
831833

832834
/*
@@ -1090,16 +1092,18 @@ private predicate sub_eq(
10901092
}
10911093

10921094
// op - x == c => op == (c+x)
1093-
private predicate sub_eq(Instruction test, Operand op, int k, boolean areEqual, AbstractValue value) {
1095+
private predicate unary_sub_eq(
1096+
Instruction test, Operand op, int k, boolean areEqual, AbstractValue value
1097+
) {
10941098
exists(SubInstruction sub, int c, int x |
1095-
compares_eq(test, sub.getAUse(), c, areEqual, value) and
1099+
unary_compares_eq(test, sub.getAUse(), c, areEqual, value) and
10961100
op = sub.getLeftOperand() and
10971101
x = int_value(sub.getRight()) and
10981102
k = c + x
10991103
)
11001104
or
11011105
exists(PointerSubInstruction sub, int c, int x |
1102-
compares_eq(test, sub.getAUse(), c, areEqual, value) and
1106+
unary_compares_eq(test, sub.getAUse(), c, areEqual, value) and
11031107
op = sub.getLeftOperand() and
11041108
x = int_value(sub.getRight()) and
11051109
k = c + x
@@ -1153,11 +1157,12 @@ private predicate add_eq(
11531157
}
11541158

11551159
// left + x == right + c => left == right + (c-x)
1156-
private predicate add_eq(
1157-
Instruction test, Operand left, int k, boolean areEqual, AbstractValue value
1160+
private predicate unary_add_eq(
1161+
Instruction test, Operand left, int k, boolean areEqual,
1162+
AbstractValue value
11581163
) {
11591164
exists(AddInstruction lhs, int c, int x |
1160-
compares_eq(test, lhs.getAUse(), c, areEqual, value) and
1165+
unary_compares_eq(test, lhs.getAUse(), c, areEqual, value) and
11611166
(
11621167
left = lhs.getLeftOperand() and x = int_value(lhs.getRight())
11631168
or
@@ -1167,7 +1172,8 @@ private predicate add_eq(
11671172
)
11681173
or
11691174
exists(PointerAddInstruction lhs, int c, int x |
1170-
compares_eq(test, lhs.getAUse(), c, areEqual, value) and
1175+
1176+
unary_compares_eq(test, lhs.getAUse(), c, areEqual, value) and
11711177
(
11721178
left = lhs.getLeftOperand() and x = int_value(lhs.getRight())
11731179
or

0 commit comments

Comments
 (0)