fbc version: 1.10.1 (2023-12-24), linux-x86_64 (official SourceForge binary release, checksum-verified against sha1sums.txt)
Command: fbc -gen llvm -O 0 repro.bas -x repro (also reproduces with -O 2)
Minimal repro
dim shared a(1) as long
dim i as long
for i = 0 to 1
a(i) = i + 1
next i
print a(0)
print a(1)
Expected output
(this is exactly what -gen gcc produces for the identical source, at both -O 0 and -O 2)
Actual output with -gen llvm
a(0) comes back holding the last iteration's value, and a(1) comes back as 0 (its true zero-initialized value) — meaning both loop iterations wrote to the same element (element 0), and element 1 was never actually written at all.
This reproduces identically at -O 0 and -O 2, so it is not an LLVM optimizer artifact — the IR that fbc itself emits for the array-element address inside the loop does not appear to depend on the loop variable's current value per iteration. It also reproduces the same way with a longer loop (every element ends up holding the last iteration's value) and with a plain, non-shared module-level array.
-gen gcc (the default backend) is unaffected and produces correct output for this exact same source.
Found while benchmarking fbc against another LLVM-emitting BASIC compiler for an unrelated project.
fbc version: 1.10.1 (2023-12-24), linux-x86_64 (official SourceForge binary release, checksum-verified against
sha1sums.txt)Command:
fbc -gen llvm -O 0 repro.bas -x repro(also reproduces with-O 2)Minimal repro
Expected output
(this is exactly what
-gen gccproduces for the identical source, at both-O 0and-O 2)Actual output with
-gen llvma(0)comes back holding the last iteration's value, anda(1)comes back as0(its true zero-initialized value) — meaning both loop iterations wrote to the same element (element 0), and element 1 was never actually written at all.This reproduces identically at
-O 0and-O 2, so it is not an LLVM optimizer artifact — the IR that fbc itself emits for the array-element address inside the loop does not appear to depend on the loop variable's current value per iteration. It also reproduces the same way with a longer loop (every element ends up holding the last iteration's value) and with a plain, non-sharedmodule-level array.-gen gcc(the default backend) is unaffected and produces correct output for this exact same source.Found while benchmarking fbc against another LLVM-emitting BASIC compiler for an unrelated project.