Bug 19320 – -cov and -O yield variable used before set
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2018-10-20T13:37:39Z
Last change time
2021-11-30T16:19:23Z
Keywords
pull
Assigned to
No Owner
Creator
Ioana Stefan
Comments
Comment #0 by ioanas96 — 2018-10-20T13:37:39Z
When building the unittest with this command:
make -f posix.mak std/array.test
I encountered the following error:
std/array.d(4179): Error: variable theArray used before set
When building the unittest for the entire hierarchy with this command:
make -f posix.mak -j8 unittest
I did not encounter the error and all the tests passed.
Comment #1 by edi33416 — 2018-12-19T13:56:49Z
Attempting to provide more context to this
Running `make -f posix.mak std/array.test`
will run
```
../dmd/generated/linux/release/64/dmd -od$T -conf= -I../druntime/import -w -de -dip25 -m64 -fPIC -transition=complex -O -release -dip1000 -main -unittest generated/linux/release/64/libphobos2.a -defaultlib= -debuglib= -L-ldl -cov -run std/array.d
```
Where $T should expand to a path similar to `/tmp/.dmd-run-test.XXXXXX`
If you remove the `-cov` flag, the tests will build without any problem.
This issue is related with the Code coverage instrumentation
Comment #2 by greeenify — 2019-05-14T23:31:02Z
Reduced with
$ dustmite --no-redirect . "~/dlang/bin/dmddev -O -cov -unittest -main array.d 2>&1 | grep 'variable theArray used before set'"
Resulting in:
$ dmd -O -cov array.d
```
auto staticArray(U, T)(T)
{
U[] theArray = void;
return theArray;
}
void main()
{
staticArray!(int, int)(3);
}
```
Making it clear that this bug is a result of -O and -cov.
Comment #3 by contact — 2021-08-23T01:24:37Z
By adding a asm block with a `nop` instruction to the affected scope, the compiler optimizer will give up searching:
asm { nop; }
Comment #4 by dlang-bot — 2021-08-23T01:32:21Z
@ljmf00 created dlang/phobos pull request #8204 "std.array: workaround for Issue 19320" mentioning this issue:
- std.array: workaround for Issue 19320
By adding a asm block with a `nop` instruction to the affected scope,
the compiler optimizer will give up searching.
https://github.com/dlang/phobos/pull/8204
Comment #5 by dlang-bot — 2021-08-25T13:22:58Z
@RazvanN7 created dlang/dmd pull request #13015 "Fix Issue 19320 - -cov and -O yield variable used before set" fixing this issue:
- Fix Issue 19320 - -cov and -O yield variable used before set
https://github.com/dlang/dmd/pull/13015
Comment #6 by razvan.nitu1305 — 2021-08-27T13:43:55Z
dlang/dmd pull request #13015 "Fix Issue 19320 - -cov and -O yield variable used before set" was merged into master:
- df0c19ec799a77b6b59bebd92ec0ed6c48870dd0 by RazvanN7:
Fix Issue 19320 - -cov and -O yield variable used before set
https://github.com/dlang/dmd/pull/13015