Repository navigation
Index Checker: refine comparison operands via nodesWithValueOf #8561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
6c2805b
7da53d8
cc3d25e
847ddeb
a90af0c
6d0da35
0c1dc85
e535d62
9044449
decfa94
edcd637
ec91366
cb80e70
c4ea38d
0331413
dd4e211
bc5f209
9970220
1b027a1
db88680
34b5d4e
d6614eb
d6f3bc3
675642e
56f8009
666211a
0945ba9
9c20c72
7e9ab4f
8506546
e47dcbc
cf8c093
75f6d6c
b228a65
f1e464c
3add1ec
9162e0e
79d6949
71cabbb
c3c07b8
a383b4a
f0801fd
e2fe758
5c88eeb
406ba7b
9f8ce62
f80904b
c677a19
d7b6c01
ab63bdc
20f1f10
00b27bc
bf4aa9b
8944dd6
bb03ffd
6ba3cb1
c25eb23
4fc4c21
ade4c68
4c39024
1364547
6dd0f64
0cca2cc
fe5ca1a
e5e3ae5
6c5aa80
5dcf941
ac967f5
d5db43c
b1d6661
77a50ce
d89bcd2
b6a284b
cf0940a
e51b950
455ce3d
073bec0
6d1557c
364ef0b
c0cf6b7
b865d1a
25687d1
c97be8e
fc65194
a483d60
c0cb6b3
651a7f0
4cf7a64
0d5276e
06a3972
05891e8
d021131
a0cc72b
390640e
dd2a276
3696c7d
0785feb
cd93fac
d37faa7
608ca1a
7b4921f
f7056ad
d356f6a
bee5a86
9dead35
934b638
2fc8be1
51a612f
bad0810
cde73f7
51a463a
86f85e3
c02d222
48a5688
77a2623
1001434
4b7d388
a668b08
7271c62
32731db
350791f
e809246
97e88f9
62f8fb5
036bfb0
c358f40
d70d366
74d27a9
7f32da1
c329d0e
919fbc1
131db9d
1250c62
4483a76
b327780
61d8d2d
73983a1
b27f5ac
cbbe62d
b71d005
ec83693
ca4f0d2
5575bd4
2a3dc0d
5d4c000
1bb6c86
82bfede
dc1566b
ea98b26
e27e322
0ab3179
92eafec
c89ae52
aaaafca
3963ac4
ebcb992
d0fcfb8
9f9d636
874f521
aa998c6
69deb24
e6ab026
5acb5dc
b753f27
8b1aa28
3e4d352
31e4df1
6c9be16
e874f18
2d0f502
36f22b8
6122ce5
f7db1d0
d087021
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |||||||||||||||||||
| import org.checkerframework.javacutil.AnnotationUtils; | ||||||||||||||||||||
| import org.checkerframework.javacutil.BugInCF; | ||||||||||||||||||||
| import org.checkerframework.javacutil.TreeUtils; | ||||||||||||||||||||
| import org.checkerframework.javacutil.TypesUtils; | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Implements dataflow refinement rules based on tests: <, >, ==, and their derivatives. | ||||||||||||||||||||
|
|
@@ -211,19 +212,11 @@ private void notEqualToValue( | |||||||||||||||||||
|
|
||||||||||||||||||||
| if (intLiteral == 0) { | ||||||||||||||||||||
| if (atypeFactory.areSameByClass(otherAnno, NonNegative.class)) { | ||||||||||||||||||||
| List<Node> internals = splitAssignments(otherNode); | ||||||||||||||||||||
| for (Node internal : internals) { | ||||||||||||||||||||
| JavaExpression je = JavaExpression.fromNode(internal); | ||||||||||||||||||||
| store.insertValue(je, POS); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| insertPositiveForComparedNode(store, otherNode); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } else if (intLiteral == -1) { | ||||||||||||||||||||
| if (atypeFactory.areSameByClass(otherAnno, GTENegativeOne.class)) { | ||||||||||||||||||||
| List<Node> internals = splitAssignments(otherNode); | ||||||||||||||||||||
| for (Node internal : internals) { | ||||||||||||||||||||
| JavaExpression je = JavaExpression.fromNode(internal); | ||||||||||||||||||||
| store.insertValue(je, NN); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| insertNonNegativeForComparedNode(store, otherNode); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
@@ -271,11 +264,63 @@ private void notEqualsLessThan( | |||||||||||||||||||
| if (!isNonNegative(leftAnno) || !isNonNegative(otherAnno)) { | ||||||||||||||||||||
| return; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| Tree leftTree = leftNode.getTree(); | ||||||||||||||||||||
| if (leftTree == null) { | ||||||||||||||||||||
| return; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| JavaExpression otherJe = JavaExpression.fromNode(otherNode); | ||||||||||||||||||||
| if (atypeFactory | ||||||||||||||||||||
| .getLessThanAnnotatedTypeFactory() | ||||||||||||||||||||
| .isLessThanOrEqual(leftNode.getTree(), otherJe.toString())) { | ||||||||||||||||||||
| store.insertValue(otherJe, POS); | ||||||||||||||||||||
| .isLessThanOrEqual(leftTree, otherJe.toString())) { | ||||||||||||||||||||
| insertPositiveForComparedNode(store, otherNode); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Refines each expression that has the value of the given node when the comparison that contains | ||||||||||||||||||||
| * the node completes (see {@link #nodesWithValueOf}), given that the value is greater than 0. | ||||||||||||||||||||
| * That implies {@code @Positive} (at least 1) for an integral expression, but only | ||||||||||||||||||||
| * {@code @NonNegative} for a floating-point expression: a value such as 0.5 is greater than 0 but | ||||||||||||||||||||
| * is less than 1. | ||||||||||||||||||||
| * | ||||||||||||||||||||
| * @param store the store to modify | ||||||||||||||||||||
| * @param node a node in an operand of a comparison, whose value is greater than 0 | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| private void insertPositiveForComparedNode(CFStore store, Node node) { | ||||||||||||||||||||
| insertValueForComparedNode(store, node, POS, NN); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Refines each expression that has the value of the given node when the comparison that contains | ||||||||||||||||||||
| * the node completes (see {@link #nodesWithValueOf}), given that the value is greater than -1. | ||||||||||||||||||||
| * That implies {@code @NonNegative} (at least 0) for an integral expression, but only | ||||||||||||||||||||
| * {@code @GTENegativeOne} for a floating-point expression: a value such as -0.5 is greater than | ||||||||||||||||||||
| * -1 but is less than 0. | ||||||||||||||||||||
| * | ||||||||||||||||||||
| * @param store the store to modify | ||||||||||||||||||||
| * @param node a node in an operand of a comparison, whose value is greater than -1 | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| private void insertNonNegativeForComparedNode(CFStore store, Node node) { | ||||||||||||||||||||
| insertValueForComparedNode(store, node, NN, GTEN1); | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
| * Inserts an annotation into the store for each expression that has the value of the given node | ||||||||||||||||||||
| * when the comparison that contains the node completes (see {@link #nodesWithValueOf}). This | ||||||||||||||||||||
| * method checks the type of each expression rather than of {@code node}, because {@code node} | ||||||||||||||||||||
| * might be a value-preserving cast such as {@code (double) i}, whose operand is integral. | ||||||||||||||||||||
| * | ||||||||||||||||||||
| * @param store the store to modify | ||||||||||||||||||||
| * @param node a node in an operand of a comparison | ||||||||||||||||||||
| * @param integralAnno the annotation to insert for an integral expression | ||||||||||||||||||||
| * @param floatingPointAnno the annotation to insert for a floating-point expression | ||||||||||||||||||||
| */ | ||||||||||||||||||||
| private void insertValueForComparedNode( | ||||||||||||||||||||
| CFStore store, Node node, AnnotationMirror integralAnno, AnnotationMirror floatingPointAnno) { | ||||||||||||||||||||
| for (Node internal : nodesWithValueOf(node)) { | ||||||||||||||||||||
| AnnotationMirror anno = | ||||||||||||||||||||
| TypesUtils.isFloatingPoint(internal.getType()) ? floatingPointAnno : integralAnno; | ||||||||||||||||||||
| store.insertValue(JavaExpression.fromNode(internal), anno); | ||||||||||||||||||||
|
Comment on lines
+320
to
+323
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose the annotation from the type of the inserted expression, not the node. The Javadoc at lines 310-311 says this method checks the type of each expression. The code checks
Select the annotation from the type of the inserted Proposed fix
Committable suggestion
|
||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
@@ -301,18 +346,18 @@ protected void refineGT( | |||||||||||||||||||
| return; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| JavaExpression leftJe = JavaExpression.fromNode(left); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // left > -1 implies left >= 0, and left > 0 implies left >= 1, only if left is integral. | ||||||||||||||||||||
| if (AnnotationUtils.areSame(rightAnno, GTEN1)) { | ||||||||||||||||||||
| store.insertValue(leftJe, NN); | ||||||||||||||||||||
| insertNonNegativeForComparedNode(store, left); | ||||||||||||||||||||
| return; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| if (AnnotationUtils.areSame(rightAnno, NN)) { | ||||||||||||||||||||
| store.insertValue(leftJe, POS); | ||||||||||||||||||||
| insertPositiveForComparedNode(store, left); | ||||||||||||||||||||
| return; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| // left > right >= 1 implies left >= 1, even if left is a floating-point value. | ||||||||||||||||||||
| if (AnnotationUtils.areSame(rightAnno, POS)) { | ||||||||||||||||||||
| store.insertValue(leftJe, POS); | ||||||||||||||||||||
| insertValueForComparedNode(store, left, POS); | ||||||||||||||||||||
| return; | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
@@ -338,14 +383,14 @@ protected void refineGTE( | |||||||||||||||||||
| return; | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| JavaExpression leftJe = JavaExpression.fromNode(left); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| AnnotationMirror newLBType = | ||||||||||||||||||||
| atypeFactory | ||||||||||||||||||||
| .getQualifierHierarchy() | ||||||||||||||||||||
| .greatestLowerBoundShallow(rightAnno, left.getType(), leftAnno, right.getType()); | ||||||||||||||||||||
|
|
||||||||||||||||||||
| store.insertValue(leftJe, newLBType); | ||||||||||||||||||||
| if (newLBType != null) { | ||||||||||||||||||||
| insertValueForComparedNode(store, left, newLBType); | ||||||||||||||||||||
| } | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| /** | ||||||||||||||||||||
|
|
||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.