Browse Source

fix issue with int literals outside int range

Michael Holman 10 năm trước cách đây
mục cha
commit
29c7fd4d49

+ 4 - 0
lib/Runtime/Language/AsmJSBytecodeGenerator.cpp

@@ -558,6 +558,10 @@ namespace Js
             {
                 return EmitExpressionInfo(mFunction->GetConstRegister<int>((uint32)pnode->sxFlt.dbl), AsmJsType::Unsigned);
             }
+            else if (pnode->sxFlt.maybeInt)
+            {
+                throw AsmJsCompilationException(L"Int literal must be in the range [-2^31, 2^32)");
+            }
             else
             {
                 return EmitExpressionInfo(mFunction->GetConstRegister<double>(pnode->sxFlt.dbl), AsmJsType::DoubleLit);

+ 8 - 1
lib/Runtime/Language/AsmJSUtils.h

@@ -62,7 +62,14 @@ namespace Js {
         static inline uint GetUInt(ParseNode *node);
         static inline bool IsNegativeZero(ParseNode* node);
         static inline bool IsMinInt(ParseNode *node){ return node && node->nop == knopFlt && node->sxFlt.maybeInt && node->sxFlt.dbl == -2147483648.0; };
-        static inline bool IsUnsigned(ParseNode *node){ return node && node->nop == knopFlt && node->sxFlt.maybeInt && (((uint32)node->sxFlt.dbl) >> 31); };
+        static inline bool IsUnsigned(ParseNode *node)
+        {
+            return node &&
+                node->nop == knopFlt &&
+                node->sxFlt.maybeInt &&
+                node->sxFlt.dbl > (double)INT_MAX &&
+                node->sxFlt.dbl <= (double)UINT_MAX;
+        }
 
         static bool IsDefinition( ParseNode *arg );
         static bool ParseVarOrConstStatement( AsmJSParser &parser, ParseNode **var );

+ 7 - 0
test/AsmJs/invalidIntLiteral.baseline

@@ -1,3 +1,10 @@
 Var declaration with integer literal outside range [-2^31, 2^32)
 Asm.js compilation failed.
 -2147483649
+
+invalidIntLiteral.js(25, 3)
+	Asm.js Compilation Error function : None::f
+	Int literal must be in the range [-2^31, 2^32)
+
+Asm.js compilation failed.
+-137438953473

+ 10 - 1
test/AsmJs/invalidIntLiteral.js

@@ -18,4 +18,13 @@ var stdlib = {}
 var env = {}
 var buffer = new ArrayBuffer(1<<20);
 var asmModule = AsmModule(stdlib,env,buffer);
-WScript.Echo(asmModule.f1());
+print(asmModule.f1());
+
+var m = function (stdlib, foreign, heap) {
+  'use asm';
+  function f() {
+    return +-137438953473;
+  }
+  return f;
+}(stdlib,env, buffer);
+print(m());

+ 4 - 4
test/AsmJs/rlexe.xml

@@ -566,16 +566,16 @@
   </test>
   <test>
     <default>
-      <files>invalidIntLiteral.js</files>
-      <baseline>invalidIntLiteral.baseline</baseline>
-      <compile-flags>-testtrace:asmjs -simdjs</compile-flags>
+      <files>floatmod.js</files>
+      <baseline>floatmod.baseline</baseline>
+      <compile-flags>-forceserialized -testtrace:asmjs -simdjs</compile-flags>
     </default>
   </test>
   <test>
     <default>
       <files>invalidIntLiteral.js</files>
       <baseline>invalidIntLiteral.baseline</baseline>
-      <compile-flags>-forceserialized -testtrace:asmjs -simdjs</compile-flags>
+      <compile-flags>-testtrace:asmjs -simdjs -force:deferparse</compile-flags>
     </default>
   </test>
   <test>