Issue 141140
Summary [HLSL] Investigate how to handle erroring/warning of out-of-bounds array access
Labels new issue
Assignees
Reporter Icohedron
    Currently, out-of-bounds array accesses are inconsistently warned about.

In trivial cases such as https://godbolt.org/z/qnoe3advn an appropriate warning is produced
```hlsl
export float test(float a4[4]) {
    return a4[5];
}
/*
<source>:2:12: warning: array index 5 is past the end of the array (that has type 'float[4]') [-Warray-bounds]
    2 |     return a4[5];
      |            ^  ~
*/
```

But in a slightly less trivial case such as https://godbolt.org/z/vs3n1bjso no warning is produced unless `-Weverything` is provided on the command-line, and the warning is for a more generic case of "unsafe buffer access".
```hlsl
export float2 test(float a4[4]) {
    return { a4[4], a4[5] };
}
/* (with -Weverything)
<source>:2:14: warning: unsafe buffer access [-Wunsafe-buffer-usage]
    2 |     return { a4[4], a4[5] };
      | ^~
<source>:2:21: warning: unsafe buffer access [-Wunsafe-buffer-usage]
    2 |     return { a4[4], a4[5] };
      | 
*/
```

The `-Warray-bounds` warning should be more consistently applied to all cases where array bounds and the index are statically determinable.

We may also want to consider treating out-of-bounds array accesses as errors rather than warnings. If we want to do so, we should also consider the implications of such a change: Do we want this to be an HLSL-specific error, or an error for all languages?  
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to