Commit e3190c21 authored by Simon Zünd's avatar Simon Zünd Committed by Commit Bot

[torque] Fix int32 literals

This CL changes the behaviour of number literals. Large integer
literals (bigger than Smi, but fit into int32) should have
type "constexpr int32" instead of "constexpr float64".

R=tebbi@chromium.org

Change-Id: I3a83c617c7d257451d299670c891fac5b21d045c
Reviewed-on: https://chromium-review.googlesource.com/1084991
Commit-Queue: Simon Zünd <szuend@google.com>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53522}
parent a938ab56
...@@ -260,6 +260,8 @@ extern implicit operator ...@@ -260,6 +260,8 @@ extern implicit operator
'convert<>' macro IntPtrConstant(constexpr int31): intptr; 'convert<>' macro IntPtrConstant(constexpr int31): intptr;
extern implicit operator extern implicit operator
'convert<>' macro Int32Constant(constexpr int31): int32; 'convert<>' macro Int32Constant(constexpr int31): int32;
extern implicit operator
'convert<>' macro Int32Constant(constexpr int32): int32;
extern implicit operator 'convert<>' macro SmiConstant(constexpr int31): Smi; extern implicit operator 'convert<>' macro SmiConstant(constexpr int31): Smi;
extern implicit operator extern implicit operator
'convert<>' macro NumberConstant(constexpr int31): Number; 'convert<>' macro NumberConstant(constexpr int31): Number;
......
...@@ -464,12 +464,10 @@ VisitResult ImplementationVisitor::Visit(NumberLiteralExpression* expr) { ...@@ -464,12 +464,10 @@ VisitResult ImplementationVisitor::Visit(NumberLiteralExpression* expr) {
const Type* result_type = const Type* result_type =
declarations()->LookupType(CONST_FLOAT64_TYPE_STRING); declarations()->LookupType(CONST_FLOAT64_TYPE_STRING);
if (i == d) { if (i == d) {
if (Internals::IsValidSmi(i)) { if ((i >> 30) == (i >> 31)) {
if (sizeof(void*) == sizeof(double) && ((i >> 30) != (i >> 31))) { result_type = declarations()->LookupType(CONST_INT31_TYPE_STRING);
result_type = declarations()->LookupType(CONST_INT32_TYPE_STRING); } else {
} else { result_type = declarations()->LookupType(CONST_INT32_TYPE_STRING);
result_type = declarations()->LookupType(CONST_INT31_TYPE_STRING);
}
} }
} }
std::string temp = GenerateNewTempVariable(result_type); std::string temp = GenerateNewTempVariable(result_type);
......
...@@ -208,4 +208,9 @@ module test { ...@@ -208,4 +208,9 @@ module test {
check(convert<intptr>(0xffff) + 1 == 0x10000); check(convert<intptr>(0xffff) + 1 == 0x10000);
check(convert<intptr>(-0xffff) == -65535); check(convert<intptr>(-0xffff) == -65535);
} }
macro TestLargeIntegerLiterals(c: Context) {
let x: int32 = 0x40000000;
let y: int32 = 0x7fffffff;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment