Array indexing in DSLX interpreter does not match IR behavior
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 283
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 135
Description
**Describe the bug**
The DSLX interpreter will error when the array index is out of bounds:
https://github.com/google/xls/blob/c59b6a21b8bc362f2899706bd74eb8ea7708644f/xls/dslx/interp_value.cc#L675-L683
However, as discussed in https://github.com/google/xls/discussions/1494, the IR documentation states:
> Any out-of-bounds indices idx_{i} are clamped to the maximum in bounds index for the respective dimension.
**To Reproduce**
```
fn foo(arr: u32[10], idx: u32) -> u32 {
arr[idx]
}
#[test]
fn foo_test() {
assert_eq(foo(u32[10]:[u32:1, ...], u32:11), u32:1);
}
```
yields the error:
> INVALID_ARGUMENT: Index out of bounds; index: 11 >= 10 elements; lhs: [u32:1, u32:1, u32:1, u32:1, u32:1, u32:1, u32:1, u32:1, u32:1, u32:1];
Contributor guide
Assessment
This issue has not been assessed yet.