C backend: fix bug in type inference, fix code generation for small int and long values

This commit is contained in:
Alexey Andreev 2018-05-04 19:05:11 +03:00
parent 4530167061
commit 899725b6bd
2 changed files with 22 additions and 18 deletions

View File

@ -30,15 +30,22 @@ public final class CodeGeneratorUtil {
} else if (value instanceof Integer) {
int i = (Integer) value;
long v = i;
if (i == Integer.MIN_VALUE) {
writer.print("(int32_t) INT32_C(0x80000000)");
} else {
if (i < 0) {
writer.print("-");
v = -i;
v = -v;
}
writer.print("INT32_C(");
writeLongConstant(writer, v);
writer.print(")");
}
} else if (value instanceof Long) {
long v = (Long) value;
if (v == Long.MIN_VALUE) {
writer.print("(int64_t) INT64_C(0x8000000000000000)");
} else {
if (v < 0) {
writer.print("-");
v = -v;
@ -46,6 +53,7 @@ public final class CodeGeneratorUtil {
writer.print("INT64_C(");
writeLongConstant(writer, v);
writer.print(")");
}
} else if (value instanceof Float) {
float f = (Float) value;
if (Float.isInfinite(f)) {

View File

@ -90,7 +90,8 @@ public class TypeInferer {
}
public VariableType typeOf(int variableIndex) {
return types[variableIndex];
VariableType result = types[variableIndex];
return result != null ? result : VariableType.OBJECT;
}
VariableType convert(ValueType type) {
@ -183,11 +184,6 @@ public class TypeInferer {
types[receiver.getIndex()] = VariableType.OBJECT;
}
@Override
public void nullConstant(VariableReader receiver) {
types[receiver.getIndex()] = VariableType.OBJECT;
}
@Override
public void nullCheck(VariableReader receiver, VariableReader value) {
builder.addEdge(value.getIndex(), receiver.getIndex());