Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Ridge2019-02-16 19:32:21 -0500
committerNathan Ridge2019-02-28 20:45:43 -0500
commit4a35647d1f145ce64b5f07f0fba3681f5d3b359a (patch)
treec8a2f5930ebc945625a2a94e03c97bc8ee5fab89 /core/org.eclipse.cdt.core/parser/org/eclipse/cdt
parent783af3dee625096e04cd7a162c3058d9d28451d1 (diff)
downloadorg.eclipse.cdt-4a35647d1f145ce64b5f07f0fba3681f5d3b359a.tar.gz
org.eclipse.cdt-4a35647d1f145ce64b5f07f0fba3681f5d3b359a.tar.xz
org.eclipse.cdt-4a35647d1f145ce64b5f07f0fba3681f5d3b359a.zip
Bug 544509 - Evaluation of negative integer cast to unsigned
Diffstat (limited to 'core/org.eclipse.cdt.core/parser/org/eclipse/cdt')
-rw-r--r--core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java19
1 files changed, 18 insertions, 1 deletions
diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java
index 73b870c5fd..1d56670dd2 100644
--- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java
+++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java
@@ -41,6 +41,7 @@ import org.eclipse.cdt.internal.core.dom.parser.CompositeValue;
import org.eclipse.cdt.internal.core.dom.parser.DependentValue;
import org.eclipse.cdt.internal.core.dom.parser.ITypeMarshalBuffer;
import org.eclipse.cdt.internal.core.dom.parser.IntegralValue;
+import org.eclipse.cdt.internal.core.dom.parser.SizeofCalculator;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPFunction;
import org.eclipse.cdt.internal.core.dom.parser.cpp.CPPPointerType;
import org.eclipse.cdt.internal.core.dom.parser.cpp.ClassTypeHelper;
@@ -189,7 +190,23 @@ public class EvalTypeId extends CPPDependentEvaluation {
}
}
if (fArguments.length == 1) {
- return fArguments[0].getValue();
+ IValue argVal = fArguments[0].getValue();
+ if (argVal instanceof IntegralValue && argVal.numberValue() != null) {
+ // Cast signed integer to unsigned.
+ Long val = argVal.numberValue().longValue();
+ if (val < 0 && inputType instanceof ICPPBasicType && ((ICPPBasicType) inputType).isUnsigned()) {
+ long sizeof = SizeofCalculator.getSizeAndAlignment(inputType).size;
+ if (sizeof > 4) {
+ // Java's "long" can't represent the full range of an 64-bit unsigned integer
+ // in C++.
+ sizeof = 4;
+ }
+ long range = (1L << (sizeof * 8 - 1));
+ val += range;
+ return IntegralValue.create(val);
+ }
+ }
+ return argVal;
}
return IntegralValue.UNKNOWN;
}

Back to the top