Repository navigation
Clarify out of bounds behavior #1722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1829,6 +1829,20 @@ The originating variable for a formal parameter of a function depends on the | |
| [=call site|call sites=] for the function. | ||
| Different call sites may supply pointers into different originating variables. | ||
|
|
||
| If a reference or pointer access is out of bounds, an <dfn noexport>invalid | ||
| memory reference</dfn> is produced. | ||
| [=Load Rule|Loads=] from an invalid reference return one of: | ||
| * a value from any [=memory locations|memory location(s)=] of the [[WebGPU#buffers|WebGPU buffer]] | ||
| bound to the [=originating variable=] | ||
| * the zero value for store type of the reference | ||
| * if the loaded value is a vector, the value (0, 0, 0, x), where x is: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. may need a bit of clarify (possibly in follow-up) on, like, what if it's |
||
| * 0, 1, or the maximum positive value for integer components | ||
| * 0.0 or 1.0 for floating-point components | ||
| [=assignment statement|Stores=] to an invalid reference may either: | ||
|
kvark marked this conversation as resolved.
Resolved
|
||
| * store the value to any [=memory locations|memory location(s)=] of the | ||
| [[WebGPU#buffers|WebGPU buffer]] bound to the [=originating variable=] | ||
| * not be executed | ||
|
dneto0 marked this conversation as resolved.
Resolved
|
||
|
|
||
| ### Use cases for references and pointers ### {#ref-ptr-use-cases} | ||
|
|
||
| References and pointers are distinguished by how they are used: | ||
|
|
@@ -3595,12 +3609,11 @@ The result type depends on the number of letters provided. Assuming a `vec4<f32> | |
| |e|[|i|]: |T| | ||
| <td>Select the |i|'<sup>th</sup> component of vector<br> | ||
| The first component is at index |i|=0.<br> | ||
| If |i| is outside the range [0,|N|-1], then an index in the range [0, |N|-1] is used instead. | ||
| If |i| is outside the range [0,|N|-1], then any valid value for |T| | ||
| may be returned. | ||
| (OpVectorExtractDynamic) | ||
| </table> | ||
|
|
||
| Issue: Which index is used when it's out of bounds? | ||
|
|
||
| #### Vector multiple component selection #### {#vector-multi-component} | ||
|
|
||
| <table class='data'> | ||
|
|
@@ -3730,9 +3743,13 @@ Issue: Which index is used when it's out of bounds? | |
| <td>|r|: ref<|SC|,vec|N|<|T|>><br> | ||
| |i|: [INT] | ||
| <td class="nowrap"> | ||
| |r|[|i|]: ref<|SC|,|T|> | ||
| <td>Compute a reference to the |i|'<sup>th</sup> component of the vector referenced by the reference |r|.<br> | ||
| If |i| is outside the range [0,|N|-1], then an index in the range [0, |N|-1] is used instead.<br> | ||
| |r|[|i|] : ref<|SC|,|T|> | ||
| <td>Compute a reference to the |i|'<sup>th</sup> component of the vector | ||
| referenced by the reference |r|. | ||
|
|
||
| If |i| is outside the range [0,|N|-1], then the expression evaluates | ||
| to [=invalid memory reference=]. | ||
|
|
||
| The [=originating variable=] of the resulting reference is | ||
| the same as the originating variable of |r|.<br> | ||
| (OpAccessChain) | ||
|
|
@@ -3753,7 +3770,8 @@ Issue: Which index is used when it's out of bounds? | |
| <td class="nowrap"> | ||
| |e|[|i|]: vec|M|<|T|> | ||
| <td>The result is the |i|'<sup>th</sup> column vector of |e|.<br> | ||
| If |i| is outside the range [0,|N|-1], then an index in the range [0, |N|-1] is used instead.<br> | ||
| If |i| is outside the range [0,|N|-1], then any valid value for | ||
| vec|M|<|T|> may be returned. | ||
| (OpCompositeExtract) | ||
| </table> | ||
|
|
||
|
|
@@ -3767,9 +3785,13 @@ Issue: Which index is used when it's out of bounds? | |
| |r|: ref<|SC|,mat|N|x|M|<|T|>><br> | ||
| |i|: [INT] | ||
| <td class="nowrap"> | ||
| |r|[|i|]: ref<vec|M|<|SC|,|T|>> | ||
| <td>Compute a reference to the |i|'<sup>th</sup> column vector of the matrix referenced by the reference |r|.<br> | ||
| If |i| is outside the range [0,|N|-1], then an index in the range [0, |N|-1] is used instead.<br> | ||
| |r|[|i|] : ref<vec|M|<|SC|,|T|>> | ||
| <td>Compute a reference to the |i|'<sup>th</sup> column vector of the | ||
| matrix referenced by the reference |r|. | ||
|
|
||
| If |i| is outside the range [0,|N|-1], then the expression evaluates to | ||
| [=invalid memory reference=]. | ||
|
|
||
| The [=originating variable=] of the resulting reference is | ||
| the same as the originating variable of |r|.<br> | ||
| (OpAccessChain) | ||
|
|
@@ -3796,9 +3818,11 @@ the variable's value, as required. | |
| |i|: [INT]<br> | ||
| |i| is a `const_expr` expression | ||
| <td class="nowrap"> | ||
| |e|[|i|]: |T| | ||
| <td>The result is the value of the |i|'<sup>th</sup> element of the array value |e|.<br> | ||
| If |i| is outside the range [0,|N|-1], then an index in the range [0, |N|-1] is used instead.<br> | ||
| |e|[|i|] : |T| | ||
| <td>The result is the value of the |i|'<sup>th</sup> element of the array value |e|. | ||
|
|
||
| If |i| is outside the range [0,|N|-1], then any valid value for |T| | ||
| may be returned. | ||
| (OpCompositeExtract) | ||
| </table> | ||
|
|
||
|
|
@@ -3812,20 +3836,28 @@ the variable's value, as required. | |
| |r|: ref<|SC|,array<|T|,|N|>><br> | ||
| |i|: [INT] | ||
| <td class="nowrap"> | ||
| |r|[|i|]: ref<|SC|,|T|> | ||
| <td>Compute a reference to the |i|'<sup>th</sup> element of the array referenced by the reference |r|.<br> | ||
| If |i| is outside the range [0,|N|-1], then an index in the range [0, |N|-1] is used instead.<br> | ||
| |r|[|i|] : ref<|SC|,|T|> | ||
| <td>Compute a reference to the |i|'<sup>th</sup> element of the array | ||
| referenced by the reference |r|. | ||
|
|
||
| If |i| is outside the range [0,|N|-1], then the expression evaluates | ||
| to an [=invalid memory reference=]. | ||
|
|
||
| The [=originating variable=] of the resulting reference is | ||
| the same as the originating variable of |r|.<br> | ||
| (OpAccessChain) | ||
| <tr algorithm="array indexed reference selection"> | ||
| <td>|r|: ref<|SC|,array<|T|>><br> | ||
| |i|: [INT] | ||
| <td class="nowrap"> | ||
| |r|[|i|]: ref<|SC|,|T|> | ||
| <td>Compute a reference to the |i|'<sup>th</sup> element of the runtime-sized array referenced by the reference |r|.<br> | ||
| If at runtime the array has |N| elements, and |i| is outside the range [0,|N|-1], then an index in the | ||
| range [0, |N|-1] is used instead.<br> | ||
| |r|[|i|] : ref<|SC|,|T|> | ||
| <td>Compute a reference to the |i|'<sup>th</sup> element of the | ||
| runtime-sized array referenced by the reference |r|. | ||
|
|
||
| If at runtime the array has |N| elements, and |i| is outside the range | ||
| [0,|N|-1], then the expression evaluates to an [=invalid memory | ||
| reference=]. | ||
|
|
||
| The [=originating variable=] of the resulting reference is | ||
| the same as the originating variable of |r|.<br> | ||
| (OpAccessChain) | ||
|
|
@@ -4344,6 +4376,10 @@ The <dfn noexport>address-of</dfn> operator converts a reference to its correspo | |
| `&`|r|: ptr<|SC|,|T|,|A|> | ||
| <td>Result is the pointer value corresponding to the | ||
| same [=memory view=] as the reference value |r|. | ||
|
|
||
| If |r| is an [=invalid memory reference=], then the resulting | ||
| pointer is also an invalid memory reference. | ||
|
|
||
| </table> | ||
|
|
||
| ## Indirection Expression ## {#indirection-expr} | ||
|
|
@@ -4362,6 +4398,10 @@ The <dfn noexport>indirection</dfn> operator converts a pointer to its correspon | |
| `*`|p|: ref<|SC|,|T|,|A|> | ||
| <td>Result is the reference value corresponding to the | ||
| same [=memory view=] as the pointer value |p|. | ||
|
|
||
| If |p| is an [=invalid memory reference=], then the resulting | ||
| reference is also an invalid memory reference. | ||
|
|
||
| </table> | ||
|
|
||
| ## Constant Identifier Expression ## {#constant-identifier-expr} | ||
|
|
@@ -4549,7 +4589,12 @@ expression to the right of the equals token is the <dfn noexport>right-hand side | |
| |SC| is a writable [=storage class=] | ||
| <td class="nowrap">|r| = |e|; | ||
| <td>Evaluates |e|, evaluates |r|, then writes the value computed for |e| into | ||
| the [=memory locations=] referenced by |r|.<br> | ||
| the [=memory locations=] referenced by |r|. | ||
|
|
||
| Note: if the reference is an [=invalid memory reference=], the write | ||
| may not execute, or may write to a different memory location than | ||
| expected. | ||
|
|
||
| (OpStore) | ||
| </table> | ||
|
|
||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.