Index: src/asmjs/asm-typer.cc |
diff --git a/src/asmjs/asm-typer.cc b/src/asmjs/asm-typer.cc |
index dff43b7db61bf4c402a2dfd3fd774cfb11c8641c..99d17e1e0bdbab6f32789479875f25802fe76a52 100644 |
--- a/src/asmjs/asm-typer.cc |
+++ b/src/asmjs/asm-typer.cc |
@@ -451,6 +451,30 @@ void AsmTyper::SetTypeOf(AstNode* node, AsmType* type) { |
} |
} |
+namespace { |
+bool IsLiteralDouble(Literal* literal) { |
+ return literal->raw_value()->IsNumber() && |
+ literal->raw_value()->ContainsDot(); |
+} |
+ |
+bool IsLiteralInt(Literal* literal) { |
+ return literal->raw_value()->IsNumber() && |
+ !literal->raw_value()->ContainsDot(); |
+} |
+ |
+bool IsLiteralMinus1(Literal* literal) { |
+ return IsLiteralInt(literal) && literal->raw_value()->AsNumber() == -1.0; |
+} |
+ |
+bool IsLiteral1Dot0(Literal* literal) { |
+ return IsLiteralDouble(literal) && literal->raw_value()->AsNumber() == 1.0; |
+} |
+ |
+bool IsLiteral0(Literal* literal) { |
+ return IsLiteralInt(literal) && literal->raw_value()->AsNumber() == 0.0; |
+} |
+} // namespace |
+ |
AsmType* AsmTyper::TypeOf(AstNode* node) const { |
auto node_type_iter = function_node_types_.find(node); |
if (node_type_iter != function_node_types_.end()) { |
@@ -464,9 +488,12 @@ AsmType* AsmTyper::TypeOf(AstNode* node) const { |
// Sometimes literal nodes are not added to the node_type_ map simply because |
// their are not visited with ValidateExpression(). |
if (auto* literal = node->AsLiteral()) { |
- if (literal->raw_value()->ContainsDot()) { |
+ if (IsLiteralDouble(literal)) { |
return AsmType::Double(); |
} |
+ if (!IsLiteralInt(literal)) { |
+ return AsmType::None(); |
+ } |
uint32_t u; |
if (literal->value()->ToUint32(&u)) { |
if (u > LargestFixNum) { |
@@ -734,8 +761,7 @@ bool IsDoubleAnnotation(BinaryOperation* binop) { |
return false; |
} |
- return right_as_literal->raw_value()->ContainsDot() && |
- right_as_literal->raw_value()->AsNumber() == 1.0; |
+ return IsLiteral1Dot0(right_as_literal); |
} |
bool IsIntAnnotation(BinaryOperation* binop) { |
@@ -748,8 +774,7 @@ bool IsIntAnnotation(BinaryOperation* binop) { |
return false; |
} |
- return !right_as_literal->raw_value()->ContainsDot() && |
- right_as_literal->raw_value()->AsNumber() == 0.0; |
+ return IsLiteral0(right_as_literal); |
} |
} // namespace |
@@ -1466,7 +1491,7 @@ bool ExtractInt32CaseLabel(CaseClause* clause, int32_t* lbl) { |
return false; |
} |
- if (lbl_expr->raw_value()->ContainsDot()) { |
+ if (!IsLiteralInt(lbl_expr)) { |
return false; |
} |
@@ -1563,8 +1588,7 @@ bool IsInvert(BinaryOperation* binop) { |
return false; |
} |
- return !right_as_literal->raw_value()->ContainsDot() && |
- right_as_literal->raw_value()->AsNumber() == -1.0; |
+ return IsLiteralMinus1(right_as_literal); |
} |
bool IsUnaryMinus(BinaryOperation* binop) { |
@@ -1578,8 +1602,7 @@ bool IsUnaryMinus(BinaryOperation* binop) { |
return false; |
} |
- return !right_as_literal->raw_value()->ContainsDot() && |
- right_as_literal->raw_value()->AsNumber() == -1.0; |
+ return IsLiteralMinus1(right_as_literal); |
} |
} // namespace |
@@ -1708,7 +1731,7 @@ AsmType* AsmTyper::ValidateNumericLiteral(Literal* literal) { |
return AsmType::Void(); |
} |
- if (literal->raw_value()->ContainsDot()) { |
+ if (IsLiteralDouble(literal)) { |
return AsmType::Double(); |
} |
@@ -1888,7 +1911,7 @@ bool IsIntishLiteralFactor(Expression* expr, int32_t* factor) { |
return false; |
} |
- if (literal->raw_value()->ContainsDot()) { |
+ if (!IsLiteralInt(literal)) { |
return false; |
} |
@@ -2297,7 +2320,7 @@ bool ExtractIndirectCallMask(Expression* expr, uint32_t* value) { |
return false; |
} |
- if (as_literal->raw_value()->ContainsDot()) { |
+ if (!IsLiteralInt(as_literal)) { |
return false; |
} |
@@ -2481,7 +2504,7 @@ bool ExtractHeapAccessShift(Expression* expr, uint32_t* value) { |
return false; |
} |
- if (as_literal->raw_value()->ContainsDot()) { |
+ if (!IsLiteralInt(as_literal)) { |
return false; |
} |
@@ -2525,7 +2548,7 @@ AsmType* AsmTyper::ValidateHeapAccess(Property* heap, |
SetTypeOf(obj, obj_type); |
if (auto* key_as_literal = heap->key()->AsLiteral()) { |
- if (key_as_literal->raw_value()->ContainsDot()) { |
+ if (!IsLiteralInt(key_as_literal)) { |
FAIL(key_as_literal, "Heap access index must be int."); |
} |
@@ -2709,9 +2732,9 @@ AsmType* AsmTyper::ReturnTypeAnnotations(ReturnStatement* statement) { |
if (auto* literal = ret_expr->AsLiteral()) { |
int32_t _; |
- if (literal->raw_value()->ContainsDot()) { |
+ if (IsLiteralDouble(literal)) { |
return AsmType::Double(); |
- } else if (literal->value()->ToInt32(&_)) { |
+ } else if (IsLiteralInt(literal) && literal->value()->ToInt32(&_)) { |
return AsmType::Signed(); |
} else if (literal->IsUndefinedLiteral()) { |
// *VIOLATION* The parser changes |
@@ -2752,13 +2775,15 @@ AsmType* AsmTyper::ReturnTypeAnnotations(ReturnStatement* statement) { |
AsmType* AsmTyper::VariableTypeAnnotations( |
Expression* initializer, VariableInfo::Mutability mutability_type) { |
if (auto* literal = initializer->AsLiteral()) { |
- if (literal->raw_value()->ContainsDot()) { |
+ if (IsLiteralDouble(literal)) { |
SetTypeOf(initializer, AsmType::Double()); |
return AsmType::Double(); |
} |
+ if (!IsLiteralInt(literal)) { |
+ FAIL(initializer, "Invalid type annotation - forbidden literal."); |
+ } |
int32_t i32; |
uint32_t u32; |
- |
AsmType* initializer_type = nullptr; |
if (literal->value()->ToUint32(&u32)) { |
if (u32 > LargestFixNum) { |