D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 15568 - Wrong contracts generated when compiled with -O
Summary: Wrong contracts generated when compiled with -O
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 regression
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-01-14 15:40 UTC by Dragos Carp
Modified: 2016-10-01 11:47 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Dragos Carp 2016-01-14 15:40:18 UTC
The PR https://github.com/D-Programming-Language/dmd/pull/4788 fixing issue https://issues.dlang.org/show_bug.cgi?id=9383 introduced a regression that can be reproduced with the following test:

---
import std.algorithm;
import std.array;

class A
{
    B foo(C c, D[] ds, bool f)
    in
    {
        assert(c !is null);
    }
    body
    {
        D[] ds2 = ds.filter!(a => c).array;

        return new B(ds2, f);
    }
}

class B
{
    this(D[], bool)
    {
    }
}

class C
{
}

struct D
{
}

unittest
{
    auto a = new A;
    C c = new C;

    a.foo(c, null, false);
}
---

It runs successfully when it is compiled with:
  dmd -unittest -main
But the contract throws AssertError when compiled with:
  dmd -unittest -main -O
Comment 1 Kenji Hara 2016-04-15 11:49:37 UTC
Issue doesn't happen in Windows platform -m32 and -m64, with git-master:
90becf651dddf4b17c1775c7c0d6ba879fb10090
Comment 2 Walter Bright 2016-05-24 01:25:10 UTC
https://github.com/dlang/dmd/pull/5803
Comment 3 Walter Bright 2016-05-24 02:19:11 UTC
This passes on all platforms in the autotester. Marking it as worksforme for now.
Comment 4 github-bugzilla 2016-05-24 03:55:30 UTC
Commits pushed to master at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/585ab7d14146ec6bc45b41e2b0b344e06dbbe1ee
test Issue 15568 - Wrong contracts generated when compiled with -O

https://github.com/dlang/dmd/commit/05a0edff93b611e2d67d5c77237092dd220afe75
Merge pull request #5803 from WalterBright/test15568

test Issue 15568 - Wrong contracts generated when compiled with -O
Comment 5 github-bugzilla 2016-10-01 11:47:06 UTC
Commits pushed to stable at https://github.com/dlang/dmd

https://github.com/dlang/dmd/commit/585ab7d14146ec6bc45b41e2b0b344e06dbbe1ee
test Issue 15568 - Wrong contracts generated when compiled with -O

https://github.com/dlang/dmd/commit/05a0edff93b611e2d67d5c77237092dd220afe75
Merge pull request #5803 from WalterBright/test15568