Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Stornelli2019-09-28 03:07:04 -0400
committerMarco Stornelli2019-10-06 03:32:08 -0400
commita781cdf342c02cc507bd7754566eb4ce6c30cf62 (patch)
tree87e49f833a9db6ee3080085513d6e3d703d17c58
parenta71a413500e2e2c29a6384bd2a375b2144582f21 (diff)
downloadorg.eclipse.cdt-a781cdf342c02cc507bd7754566eb4ce6c30cf62.tar.gz
org.eclipse.cdt-a781cdf342c02cc507bd7754566eb4ce6c30cf62.tar.xz
org.eclipse.cdt-a781cdf342c02cc507bd7754566eb4ce6c30cf62.zip
Bug 343274 - Fix VariableReadWriteFlags errors
Read and write flags weren't correctly set for array access. Change-Id: I2c54b270895514f3681903709498aa9344a5bc7e Signed-off-by: Marco Stornelli <marco.stornelli@gmail.com>
-rw-r--r--core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/VariableReadWriteFlagsTest.java16
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java23
2 files changed, 39 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/VariableReadWriteFlagsTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/VariableReadWriteFlagsTest.java
index 2f024e8cd3..5eb63ee371 100644
--- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/VariableReadWriteFlagsTest.java
+++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/core/parser/tests/ast2/VariableReadWriteFlagsTest.java
@@ -229,4 +229,20 @@ public class VariableReadWriteFlagsTest extends AST2TestBase {
a.assertReadWriteFlags("variadic(waldo)", "waldo", READ);
a.assertReadWriteFlags("variadic(&waldo)", "waldo", READ | WRITE);
}
+
+ // int arr[5];
+ // int test() {
+ // arr[0];
+ // arr[0] = 1;
+ // int a;
+ // a = arr[0];
+ // return arr[0];
+ // }
+ public void testArraySubscript() throws Exception {
+ AssertionHelper a = getCPPAssertionHelper();
+ a.assertReadWriteFlags("arr[0];", "arr", READ);
+ a.assertReadWriteFlags("arr[0] = 1", "arr", READ | WRITE);
+ a.assertReadWriteFlags("a = arr[0];", "arr", READ);
+ a.assertReadWriteFlags("return arr[0];", "arr", READ);
+ }
}
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java
index fb757d85f8..a7bc98a904 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/VariableReadWriteFlags.java
@@ -132,6 +132,24 @@ public abstract class VariableReadWriteFlags {
}
}
+ private boolean isAssignment(IASTBinaryExpression node) {
+ switch (node.getOperator()) {
+ case IASTBinaryExpression.op_assign:
+ case IASTBinaryExpression.op_binaryAndAssign:
+ case IASTBinaryExpression.op_binaryOrAssign:
+ case IASTBinaryExpression.op_binaryXorAssign:
+ case IASTBinaryExpression.op_divideAssign:
+ case IASTBinaryExpression.op_minusAssign:
+ case IASTBinaryExpression.op_moduloAssign:
+ case IASTBinaryExpression.op_multiplyAssign:
+ case IASTBinaryExpression.op_plusAssign:
+ case IASTBinaryExpression.op_shiftLeftAssign:
+ case IASTBinaryExpression.op_shiftRightAssign:
+ return true;
+ }
+ return false;
+ }
+
protected int rwInExpression(IASTExpression expr, IASTNode node, int indirection) {
if (expr instanceof IASTIdExpression) {
return rwAnyNode(expr, indirection);
@@ -152,6 +170,11 @@ public abstract class VariableReadWriteFlags {
if (indirection > 0 && node.getPropertyInParent() == IASTArraySubscriptExpression.ARRAY) {
return rwAnyNode(expr, indirection - 1);
}
+ if (expr.getParent() instanceof IASTBinaryExpression
+ && expr.getPropertyInParent() == IASTBinaryExpression.OPERAND_ONE
+ && isAssignment((IASTBinaryExpression) expr.getParent())) {
+ return READ | WRITE;
+ }
return READ;
}
if (expr instanceof IASTConditionalExpression) {

Back to the top