Skip to content

Commit 404e79f

Browse files
authored
Merge pull request WebAssembly#509 from WebAssembly/fix.508
[spec] Fix prose for bounds check in array.init_data/elem
2 parents cd9bfba + 9d9fb98 commit 404e79f

File tree

1 file changed

+29
-37
lines changed

1 file changed

+29
-37
lines changed

document/core/exec/instructions.rst

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,47 +1341,43 @@ Where:
13411341

13421342
19. Assert: due to :ref:`validation <valid-array.init_data>`, the :ref:`array instance <syntax-arrayinst>` :math:`S.\SARRAYS[a]` exists.
13431343

1344-
20. If :math:`d + n` is larger than or equal to the length of :math:`S.\SARRAYS[a].\AIFIELDS`, then:
1344+
20. Assert: due to :ref:`validation <valid-array.init_data>`, the :ref:`field type <syntax-fieldtype>` :math:`\X{ft}` has a defined :ref:`bit width <bitwidth-fieldtype>`.
13451345

1346-
a. Trap.
1347-
1348-
21. Assert: due to :ref:`validation <valid-array.init_data>`, the :ref:`field type <syntax-fieldtype>` :math:`\X{ft}` has a defined :ref:`bit width <bitwidth-fieldtype>`.
1346+
21. Let :math:`z` be the :ref:`bit width <bitwidth-fieldtype>` of :ref:`field type <syntax-fieldtype>` :math:`\X{ft}` divided by eight.
13491347

1350-
22. Let :math:`z` be the :ref:`bit width <bitwidth-fieldtype>` of :ref:`field type <syntax-fieldtype>` :math:`\X{ft}` divided by eight.
1351-
1352-
23. If the sum of :math:`s` and :math:`n` times :math:`z` is larger than the length of :math:`\datainst.\DIDATA`, then:
1348+
22. If :math:`d + n` is larger than the length of :math:`S.\SARRAYS[a].\AIFIELDS`, or the sum of :math:`s` and :math:`n` times :math:`z` is larger than the length of :math:`\datainst.\DIDATA`, then:
13531349

13541350
a. Trap.
13551351

1356-
24. If :math:`n = 0`, then:
1352+
23. If :math:`n = 0`, then:
13571353

13581354
a. Return.
13591355

1360-
25. Let :math:`b^\ast` be the :ref:`byte <syntax-byte>` sequence :math:`\datainst.\DIDATA[s \slice z]`.
1356+
24. Let :math:`b^\ast` be the :ref:`byte <syntax-byte>` sequence :math:`\datainst.\DIDATA[s \slice z]`.
13611357

1362-
26. Let :math:`t` be the :ref:`value type <syntax-valtype>` :math:`\unpacktype(\X{ft})`.
1358+
25. Let :math:`t` be the :ref:`value type <syntax-valtype>` :math:`\unpacktype(\X{ft})`.
13631359

1364-
27. Assert: due to :ref:`validation <valid-array.init_data>`, :math:`\bytes_{\X{ft}}` is defined.
1360+
26. Assert: due to :ref:`validation <valid-array.init_data>`, :math:`\bytes_{\X{ft}}` is defined.
13651361

1366-
28. Let :math:`c` be the constant for which :math:`\bytes_{\X{ft}}(c)` is :math:`b^\ast`.
1362+
27. Let :math:`c` be the constant for which :math:`\bytes_{\X{ft}}(c)` is :math:`b^\ast`.
13671363

1368-
29. Push the value :math:`\REFARRAYADDR~a` to the stack.
1364+
28. Push the value :math:`\REFARRAYADDR~a` to the stack.
13691365

1370-
30. Push the value :math:`\I32.\CONST~d` to the stack.
1366+
29. Push the value :math:`\I32.\CONST~d` to the stack.
13711367

1372-
31. Push the value :math:`t.\CONST~c` to the stack.
1368+
30. Push the value :math:`t.\CONST~c` to the stack.
13731369

1374-
32. Execute the instruction :math:`\ARRAYSET~x`.
1370+
31. Execute the instruction :math:`\ARRAYSET~x`.
13751371

1376-
33. Push the value :math:`\REFARRAYADDR~a` to the stack.
1372+
32. Push the value :math:`\REFARRAYADDR~a` to the stack.
13771373

1378-
34. Push the value :math:`\I32.\CONST~(d+1)` to the stack.
1374+
33. Push the value :math:`\I32.\CONST~(d+1)` to the stack.
13791375

1380-
35. Push the value :math:`\I32.\CONST~(s+z)` to the stack.
1376+
34. Push the value :math:`\I32.\CONST~(s+z)` to the stack.
13811377

1382-
36. Push the value :math:`\I32.\CONST~(n-1)` to the stack.
1378+
35. Push the value :math:`\I32.\CONST~(n-1)` to the stack.
13831379

1384-
37. Execute the instruction :math:`\ARRAYINITDATA~x~y`.
1380+
36. Execute the instruction :math:`\ARRAYINITDATA~x~y`.
13851381

13861382
.. math::
13871383
~\\[-1ex]
@@ -1462,37 +1458,33 @@ Where:
14621458

14631459
19. Assert: due to :ref:`validation <valid-array.init_elem>`, the :ref:`array instance <syntax-arrayinst>` :math:`S.\SARRAYS[a]` exists.
14641460

1465-
20. If :math:`d + n` is larger than or equal to the length of :math:`S.\SARRAYS[a].\AIFIELDS`, then:
1461+
20. If :math:`d + n` is larger than the length of :math:`S.\SARRAYS[a].\AIFIELDS`, or :math:`s + n` is larger than the length of :math:`\eleminst.\EIELEM`, then:
14661462

14671463
a. Trap.
14681464

1469-
21. If :math:`s + n` is larger than or equal to the length of :math:`\eleminst.\EIELEM`, then:
1470-
1471-
a. Trap.
1472-
1473-
22. If :math:`n = 0`, then:
1465+
21. If :math:`n = 0`, then:
14741466

14751467
a. Return.
14761468

1477-
23. Let :math:`\reff'` be the :ref:`reference value <syntax-ref>` :math:`\eleminst.\EIELEM[s]`.
1469+
22. Let :math:`\reff'` be the :ref:`reference value <syntax-ref>` :math:`\eleminst.\EIELEM[s]`.
14781470

1479-
24. Push the value :math:`\REFARRAYADDR~a` to the stack.
1471+
23. Push the value :math:`\REFARRAYADDR~a` to the stack.
14801472

1481-
25. Push the value :math:`\I32.\CONST~d` to the stack.
1473+
24. Push the value :math:`\I32.\CONST~d` to the stack.
14821474

1483-
26. Push the value :math:`\reff'` to the stack.
1475+
25. Push the value :math:`\reff'` to the stack.
14841476

1485-
27. Execute the instruction :math:`\ARRAYSET~x`.
1477+
26. Execute the instruction :math:`\ARRAYSET~x`.
14861478

1487-
28. Push the value :math:`\REFARRAYADDR~a` to the stack.
1479+
27. Push the value :math:`\REFARRAYADDR~a` to the stack.
14881480

1489-
29. Push the value :math:`\I32.\CONST~(d+1)` to the stack.
1481+
28. Push the value :math:`\I32.\CONST~(d+1)` to the stack.
14901482

1491-
30. Push the value :math:`\I32.\CONST~(s+1)` to the stack.
1483+
29. Push the value :math:`\I32.\CONST~(s+1)` to the stack.
14921484

1493-
31. Push the value :math:`\I32.\CONST~(n-1)` to the stack.
1485+
30. Push the value :math:`\I32.\CONST~(n-1)` to the stack.
14941486

1495-
32. Execute the instruction :math:`\ARRAYINITELEM~x~y`.
1487+
31. Execute the instruction :math:`\ARRAYINITELEM~x~y`.
14961488

14971489
.. math::
14981490
~\\[-1ex]

0 commit comments

Comments
 (0)