Skip to content

[HLSL] Investigate how to handle erroring/warning of out-of-bounds vector access #141144

@Icohedron

Description

@Icohedron

Currently, Clang does not emit a warning or error upon encountering an out-of-bounds vector index.
This does not match DXC behavior, which emits an error

https://godbolt.org/z/3Mfjvn5Ex

export float test(float4 v4) {
    return v4[5];
}
/* DXC output
<source>:2:15: error: vector element index '5' is out of bounds
    return v4[5];
              ^
*/

https://godbolt.org/z/zGc9ox5d1

export float2 test(float4 v4) {
    float2 res = { v4[4], v4[5] };
    return res;
}
/* DXC output
error: validation errors
<source>:3:5: error: Instructions should not read uninitialized value.
note: at 'ret <2 x float> undef' in block '#0' of function '�?test@@YA?AV?$vector@M$01@@V?$vector@M$03@@@Z'.
Validation failed.
*/

Should we match DXC behavior and error upon encountering an out-of-bounds vector index? Or should we simply create a warning?
Should we error/warn only for HLSL, or for all languages? Perhaps error for HLSL but warn for all other languages?

An error for out-of-bounds vector indexing has attempted to be implemented before (#128952), but it broke builds (see #128952 (comment)).

We should also consider what @efriedma-quic mentioned (#128952 (comment)) about generally not wanting to have differing semantic rules based on whether or not a value is constant.

Metadata

Metadata

Assignees

No one assigned

    Labels

    HLSLHLSL Language Support

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions