Thread overview
[Issue 19320] -cov and -O yield variable used before set
[Issue 19320] Unittest error: Variable used before set in std/array.d
Dec 19, 2018
Eduard Staniloiu
May 14, 2019
Seb
Nov 28, 2019
berni44
Aug 23, 2021
Luís Ferreira
Aug 23, 2021
Dlang Bot
Aug 25, 2021
Dlang Bot
Aug 27, 2021
RazvanN
Nov 30, 2021
Dlang Bot
December 19, 2018
https://issues.dlang.org/show_bug.cgi?id=19320

Eduard Staniloiu <edi33416@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |edi33416@gmail.com

--- Comment #1 from Eduard Staniloiu <edi33416@gmail.com> ---
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

--
May 14, 2019
https://issues.dlang.org/show_bug.cgi?id=19320

Seb <greeenify@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |greeenify@gmail.com
            Summary|Unittest error: Variable    |-cov and -O yield variable
                   |used before set in          |used before set
                   |std/array.d                 |

--- Comment #2 from Seb <greeenify@gmail.com> ---
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.

--
November 28, 2019
https://issues.dlang.org/show_bug.cgi?id=19320

berni44 <bugzilla@d-ecke.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@d-ecke.de
          Component|phobos                      |dmd

--
August 23, 2021
https://issues.dlang.org/show_bug.cgi?id=19320

Luís Ferreira <lsferreira169@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lsferreira169@gmail.com

--- Comment #3 from Luís Ferreira <lsferreira169@gmail.com> ---
By adding a asm block with a `nop` instruction to the affected scope, the compiler optimizer will give up searching:

asm { nop; }

--
August 23, 2021
https://issues.dlang.org/show_bug.cgi?id=19320

--- Comment #4 from Dlang Bot <dlang-bot@dlang.rocks> ---
@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

--
August 25, 2021
https://issues.dlang.org/show_bug.cgi?id=19320

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull

--- Comment #5 from Dlang Bot <dlang-bot@dlang.rocks> ---
@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

--
August 27, 2021
https://issues.dlang.org/show_bug.cgi?id=19320

RazvanN <razvan.nitu1305@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |razvan.nitu1305@gmail.com

--- Comment #6 from RazvanN <razvan.nitu1305@gmail.com> ---
Simplified:

int[] staticArray(int)
{
    int[] theArray = void;
    return theArray;
}


void main()
{
    staticArray(3);
}

--
November 30, 2021
https://issues.dlang.org/show_bug.cgi?id=19320

Dlang Bot <dlang-bot@dlang.rocks> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #7 from Dlang Bot <dlang-bot@dlang.rocks> ---
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

--