Ver Fonte

Disallow const globals to be used in init_expr
Update memory.wast from the spec repo

Michael Ferris há 9 anos atrás
pai
commit
a0857b2c7b

+ 4 - 4
lib/WasmReader/WasmBinaryReader.cpp

@@ -942,10 +942,6 @@ WasmBinaryReader::ReadGlobalsSection()
             m_module->AddGlobal(GlobalReferenceTypes::Const, type, isMutable, globalNode);
             break;
         case  wbGetGlobal:
-            if (m_module->GetGlobal(globalNode.var.num)->GetReferenceType() != GlobalReferenceTypes::ImportedReference)
-            {
-                ThrowDecodingError(_u("Global can only be initialized with a const or an imported global"));
-            }
             m_module->AddGlobal(GlobalReferenceTypes::LocalReference, type, isMutable, globalNode);
             break;
         default:
@@ -1155,6 +1151,10 @@ WasmBinaryReader::ReadInitExpr(bool isOffset)
     {
         uint32 globalIndex = node.var.num;
         WasmGlobal* global = m_module->GetGlobal(globalIndex);
+        if (global->GetReferenceType() != GlobalReferenceTypes::ImportedReference)
+        {
+            ThrowDecodingError(_u("initializer expression can only use imported globals"));
+        }
         if (global->IsMutable())
         {
             ThrowDecodingError(_u("initializer expression cannot reference a mutable global"));

BIN
test/WasmSpec/testsuite-bin/memory.10.wasm


BIN
test/WasmSpec/testsuite-bin/memory.11.wasm


BIN
test/WasmSpec/testsuite-bin/memory.12.wasm


BIN
test/WasmSpec/testsuite-bin/memory.13.wasm


BIN
test/WasmSpec/testsuite-bin/memory.14.wasm


BIN
test/WasmSpec/testsuite-bin/memory.15.wasm


BIN
test/WasmSpec/testsuite-bin/memory.16.wasm


BIN
test/WasmSpec/testsuite-bin/memory.17.wasm


BIN
test/WasmSpec/testsuite-bin/memory.18.wasm


BIN
test/WasmSpec/testsuite-bin/memory.19.wasm


BIN
test/WasmSpec/testsuite-bin/memory.20.wasm


BIN
test/WasmSpec/testsuite-bin/memory.21.wasm


BIN
test/WasmSpec/testsuite-bin/memory.22.wasm


BIN
test/WasmSpec/testsuite-bin/memory.23.wasm


BIN
test/WasmSpec/testsuite-bin/memory.24.wasm


BIN
test/WasmSpec/testsuite-bin/memory.25.wasm


BIN
test/WasmSpec/testsuite-bin/memory.9.wasm


+ 35 - 41
test/WasmSpec/testsuite-bin/memory.json

@@ -34,34 +34,34 @@
     "commands": []
   }, {
     "filename": "memory.11.wasm",
-    "commands": []
-  }, {
-    "filename": "memory.12.wasm",
-    "commands": []
-  }, {
-    "filename": "memory.13.wasm",
     "commands": [{
       "type": "assert_return",
       "name": "$assert_return_0",
       "file": "memory.wast",
-      "line": 19
+      "line": 20
     }]
   }, {
-    "filename": "memory.14.wasm",
+    "filename": "memory.12.wasm",
     "commands": [{
       "type": "assert_return",
       "name": "$assert_return_0",
       "file": "memory.wast",
-      "line": 21
+      "line": 22
     }]
   }, {
-    "filename": "memory.15.wasm",
+    "filename": "memory.13.wasm",
     "commands": [{
       "type": "assert_return",
       "name": "$assert_return_0",
       "file": "memory.wast",
-      "line": 23
+      "line": 24
     }]
+  }, {
+    "filename": "memory.14.wasm",
+    "commands": []
+  }, {
+    "filename": "memory.15.wasm",
+    "commands": []
   }, {
     "filename": "memory.16.wasm",
     "commands": []
@@ -85,132 +85,126 @@
     "commands": []
   }, {
     "filename": "memory.23.wasm",
-    "commands": []
-  }, {
-    "filename": "memory.24.wasm",
-    "commands": []
-  }, {
-    "filename": "memory.25.wasm",
     "commands": [{
       "type": "assert_return",
       "name": "$assert_return_0",
       "file": "memory.wast",
-      "line": 281
+      "line": 283
     }, {
       "type": "assert_return",
       "name": "$assert_return_1",
       "file": "memory.wast",
-      "line": 282
+      "line": 284
     }, {
       "type": "assert_return",
       "name": "$assert_return_2",
       "file": "memory.wast",
-      "line": 283
+      "line": 285
     }, {
       "type": "assert_return",
       "name": "$assert_return_3",
       "file": "memory.wast",
-      "line": 284
+      "line": 286
     }, {
       "type": "assert_return",
       "name": "$assert_return_4",
       "file": "memory.wast",
-      "line": 286
+      "line": 288
     }, {
       "type": "assert_return",
       "name": "$assert_return_5",
       "file": "memory.wast",
-      "line": 287
+      "line": 289
     }, {
       "type": "assert_return",
       "name": "$assert_return_6",
       "file": "memory.wast",
-      "line": 288
+      "line": 290
     }, {
       "type": "assert_return",
       "name": "$assert_return_7",
       "file": "memory.wast",
-      "line": 289
+      "line": 291
     }, {
       "type": "assert_return",
       "name": "$assert_return_8",
       "file": "memory.wast",
-      "line": 291
+      "line": 293
     }, {
       "type": "assert_return",
       "name": "$assert_return_9",
       "file": "memory.wast",
-      "line": 292
+      "line": 294
     }, {
       "type": "assert_return",
       "name": "$assert_return_10",
       "file": "memory.wast",
-      "line": 293
+      "line": 295
     }, {
       "type": "assert_return",
       "name": "$assert_return_11",
       "file": "memory.wast",
-      "line": 294
+      "line": 296
     }, {
       "type": "assert_return",
       "name": "$assert_return_12",
       "file": "memory.wast",
-      "line": 296
+      "line": 298
     }, {
       "type": "assert_return",
       "name": "$assert_return_13",
       "file": "memory.wast",
-      "line": 297
+      "line": 299
     }, {
       "type": "assert_return",
       "name": "$assert_return_14",
       "file": "memory.wast",
-      "line": 298
+      "line": 300
     }, {
       "type": "assert_return",
       "name": "$assert_return_15",
       "file": "memory.wast",
-      "line": 299
+      "line": 301
     }, {
       "type": "assert_return",
       "name": "$assert_return_16",
       "file": "memory.wast",
-      "line": 300
+      "line": 302
     }, {
       "type": "assert_return",
       "name": "$assert_return_17",
       "file": "memory.wast",
-      "line": 301
+      "line": 303
     }, {
       "type": "assert_return",
       "name": "$assert_return_18",
       "file": "memory.wast",
-      "line": 303
+      "line": 305
     }, {
       "type": "assert_return",
       "name": "$assert_return_19",
       "file": "memory.wast",
-      "line": 304
+      "line": 306
     }, {
       "type": "assert_return",
       "name": "$assert_return_20",
       "file": "memory.wast",
-      "line": 305
+      "line": 307
     }, {
       "type": "assert_return",
       "name": "$assert_return_21",
       "file": "memory.wast",
-      "line": 306
+      "line": 308
     }, {
       "type": "assert_return",
       "name": "$assert_return_22",
       "file": "memory.wast",
-      "line": 307
+      "line": 309
     }, {
       "type": "assert_return",
       "name": "$assert_return_23",
       "file": "memory.wast",
-      "line": 308
+      "line": 310
     }]
   }]
 }

+ 11 - 9
test/WasmSpec/testsuite/memory.wast

@@ -10,10 +10,11 @@
 (module (memory 1 2)
   (data (i32.const 0) "a") (data (i32.const 1) "b") (data (i32.const 2) "c")
 )
-(module (memory 1) (global i32 (i32.const 0)) (data (get_global 0) "a"))
-(module (memory 1) (global $g i32 (i32.const 0)) (data (get_global $g) "a"))
-(module (memory 1) (data (get_global 0) "a") (global i32 (i32.const 0)))
-(module (memory 1) (data (get_global $g) "a") (global $g i32 (i32.const 0)))
+(module (global (import "spectest" "global") i32) (memory 1) (data (get_global 0) "a"))
+(module (global $g (import "spectest" "global") i32) (memory 1) (data (get_global $g) "a"))
+;; Use of internal globals in constant expressions is not allowed in MVP.
+;; (module (memory 1) (data (get_global 0) "a") (global i32 (i32.const 0)))
+;; (module (memory 1) (data (get_global $g) "a") (global $g i32 (i32.const 0)))
 
 (module (memory (data)) (func (export "memsize") (result i32) (current_memory)))
 (assert_return (invoke "memsize") (i32.const 0))
@@ -38,10 +39,11 @@
   (module (memory 1) (data (nop)))
   "constant expression required"
 )
-(assert_invalid
-  (module (memory 1) (data (get_global $g)) (global $g (mut i32) (i32.const 0)))
-  "constant expression required"
-)
+;; Use of internal globals in constant expressions is not allowed in MVP.
+;; (assert_invalid
+;;   (module (memory 1) (data (get_global $g)) (global $g (mut i32) (i32.const 0)))
+;;   "constant expression required"
+;; )
 
 (assert_unlinkable
   (module (memory 0 0) (data (i32.const 0) "a"))
@@ -57,7 +59,7 @@
   ""  ;; either out of memory or segment does not fit
 ;)
 (assert_unlinkable
-  (module (memory 1) (data (get_global 0) "a") (global i32 (i32.const 0x10000)))
+  (module (global (import "spectest" "global") i32) (memory 0) (data (get_global 0) "a"))
   "data segment does not fit"
 )
 

+ 1 - 1
test/wasm/baselines/global.baseline

@@ -60,4 +60,4 @@ impInit: 78.145
 Invalid cases
 Should be invalid type conversion: Invalid WebAssembly type conversion
 Should be invalid type conversion: Invalid WebAssembly type conversion
-Should be invalid init expr: Global can only be initialized with a const or an imported global
+Should be invalid init expr: initializer expression can only use imported globals

+ 0 - 4
test/wasm/table.baseline

@@ -2,10 +2,6 @@
 25
 35
 45
-55
-65
-75
-85
 35
 45
 55

+ 2 - 0
test/wasm/table.js

@@ -13,10 +13,12 @@ print(a1.call(3));
 print(a1.call(4));
 
 //global offset
+/* const global in init expr not supported in MVP
 print(a1.call(6));
 print(a1.call(7));
 print(a1.call(8));
 print(a1.call(9));
+*/
 
 //imported global offset
 print(a1.call(10));

BIN
test/wasm/table.wasm


+ 3 - 3
test/wasm/table.wast

@@ -9,12 +9,12 @@
 
   (global $x (import "m" "x") i32)
   (global $a i32 (i32.const 6))
-  
+
   (table 15 anyfunc)
     (elem (i32.const 1)    $g1 $g2 $g3 $g4) ;;local offset
     (elem (get_global $x)  $g3 $g4 $g5 $g6) ;;imported global offset
-    (elem (get_global $a)  $g5 $g6 $g7 $g8) ;;global offset
-  
+    ;;(elem (get_global $a)  $g5 $g6 $g7 $g8) ;;global offset
+
   (func $g1 (result i32) (i32.const 15))
   (func $g2 (result i32) (i32.const 25))
   (func $g3 (result i32) (i32.const 35))