Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2017-11-06 04:49:47 +0000
committerNathan Ridge2017-11-13 18:25:32 +0000
commitf1f9ddf0f70bdc5a4960803b47c6137a5d2486d4 (patch)
tree6b768075b305d11cbc06b32c98dff4deb2f1a160 /core/org.eclipse.cdt.core
parent301de3d40ea15dfc84a90c227db62514cd2dc578 (diff)
downloadorg.eclipse.cdt-f1f9ddf0f70bdc5a4960803b47c6137a5d2486d4.tar.gz
org.eclipse.cdt-f1f9ddf0f70bdc5a4960803b47c6137a5d2486d4.tar.xz
org.eclipse.cdt-f1f9ddf0f70bdc5a4960803b47c6137a5d2486d4.zip
Bug 514363 - Fix constexpr evaluation of assignment into array element
The computation had a bug where the array decayed to a pointer, and we tried to use the pointer's value as a composite value, instead of the underlying array's value. Change-Id: I9510d28e04deb0b8ef835e2857f8b513d11d1d72
Diffstat (limited to 'core/org.eclipse.cdt.core')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java14
1 files changed, 13 insertions, 1 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java
index 8e878f83ea8..4169813f585 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalBinary.java
@@ -491,7 +491,19 @@ public class EvalBinary extends CPPDependentEvaluation {
Number numericValue = fixed2.getValue().numberValue();
if (numericValue == null)
return EvalFixed.INCOMPLETE;
- return new EvalCompositeAccess(fixed1, numericValue.intValue());
+ ICPPEvaluation composite = fixed1;
+ int arrayIndex = numericValue.intValue();
+ if (fixed1 instanceof EvalPointer) {
+ ICPPEvaluation elementEval = ((EvalPointer) fixed1).getTargetEvaluation();
+ if (elementEval instanceof EvalCompositeAccess) {
+ // 'composite' will now be the underlying array that the pointer points into.
+ // Since the pointer may not point at the beginning of the array, the array
+ // index needs to be shifted by the pointer's position.
+ composite = ((EvalCompositeAccess) elementEval).getParent();
+ arrayIndex += ((EvalPointer) fixed1).getPosition();
+ }
+ }
+ return new EvalCompositeAccess(composite, arrayIndex);
} else if ((isArray(fixed1) || isArray(fixed2)) && (hasIntType(fixed1) || hasIntType(fixed2))) {
int offset = hasIntType(fixed1) ? fixed1.getValue().numberValue().intValue() : fixed2.getValue().numberValue().intValue();
EvalCompositeAccess evalCompositeAccess = new EvalCompositeAccess(isArray(fixed1) ? fixed1 : fixed2, offset);

Back to the top