AccelerateHS / AccelerateHS/accelerate-llvm

[BUG] Conditional does not gate memory access unless in top-level expression

Offen
#116 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Haskell
Sterne
171
Forks
65
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.