AccelerateHS / AccelerateHS/accelerate-llvm
[BUG] Conditional does not gate memory access unless in top-level expression
- Dominant language
- Haskell
- Stars
- 171
- Forks
- 65
- PR merge metrics
- No merged PRs in 30d
Description
To prevent out-of-bounds accesses, conditionals (i.e. `?` operator or `cond`) can be used to check bounds ahead of accessing those arrays. For example the following correctly guards against OOB access:
```
foo = generate (I1 10) $ \(I1 i) ->
i < length bar ? (bar !! i, 0)
```
however, the following does not generate code which correctly guards against OOB access but should:
```
foo = generate (I1 10) $ \(I1 i) ->
T2 (i < length bar ? (bar !! i, 0))
(i < length bar ? ((bar !! i) + 1, 1))
```
This is not an exact reproduction of my scenario but it is similar. Principally what I observer in the generated LLVM output is the `bar` access taking place without first checking if `i < length bar`. This has lead to OOB accesses. When I instead do the following:
```
foo = generate (I1 10) $ \(I1 i) ->
i < length bar ? (T2 (bar !! i) ((bar !! i) + 1), T2 0 1)
```
the OOB access disappears.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.