D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 10540 - variable used before set for empty static arrays, with -inline -O
Summary: variable used before set for empty static arrays, with -inline -O
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL: http://forum.dlang.org/thread/khdhvzf...
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2013-07-04 02:15 UTC by monarchdodra
Modified: 2017-07-19 03:28 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description monarchdodra 2013-07-04 02:15:47 UTC
Thread:
http://forum.dlang.org/thread/khdhvzfdfljbtlyfqocw@forum.dlang.org#post-khdhvzfdfljbtlyfqocw:40forum.dlang.org

When compiled with -O -inline:
--------
struct S
{
    int[0] a;

    void do_it()
    {
        foo(a);
    }
}

void foo(Args...)(Args args)
{
    //foreach(arg; args)
    //    if (arg.ptr == null)
    //        return;

    bar(args);
}

void bar(Args...)(Args args)
{
    foreach(arg; args)
        if (arg.ptr == null)
            return;
}

void main()
{}
--------
Produces:
main.d(11): Error: variable _param_0 used before set
--------

Possibly the compiler optimizes out a's initialization, since it is an empty static array.

Code is glitchy: Not only does the bug appear only in bar (and not foo), un-commenting the code in foo will *fix* the call in bar...
Comment 1 monarchdodra 2013-07-04 02:16:29 UTC
Possibly related:
http://d.puremagic.com/issues/show_bug.cgi?id=7953
Comment 2 Vladimir Panteleev 2017-07-19 03:28:24 UTC
No longer reproducible after https://github.com/dlang/dmd/pull/3467, closing. Please reopen if you can still provide a reproducible test case.