www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11447] New: Closure provide bogus values

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447

           Summary: Closure provide bogus values
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: deadalnix gmail.com



Created an attachment (id=1287)
Full source code.

Executive summary, full code in the archive attached.

        auto instanciateFromResolvedArgs(Location , Template t,
TemplateArgument[] args) {

                static Template gladeulfeurah;
                gladeulfeurah = t;
                string id = args.map!(
({
                        }, delegate string(identified) {
                                assert(t is gladeulfeurah, "tagazok");
                                        assert(0);
                        })
                ).join;
        }

Here, assert(t is gladeulfeurah, "tagazok") fails, when it should succeeed.
Significant part of SDC test suite fail due to this bug (SDC crashes as a
result).

To compile what is provided in the archive :
make DMD=PATH_TO_DMD_MASTER
Run with :
LD_LIBRARY_PATH=PATH_TO_PHOBOS_MASTER ./fail

The whole source code to trigger the error is 3 source file, so it isn't that
big.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 05 2013
next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447


Vladimir Panteleev <thecybershadow gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thecybershadow gmail.com
           Severity|major                       |regression



10:22:20 EET ---
OP elaborated on IRC that this is a regression from 2.063.2. The included
sample is not fully reduced (DustMite run + cursory Makefile cleanup), but
according to OP, separate compilation is required to reproduce the bug.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 16 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447




OK, I've been able to spend some time making this report look better.

a.d :
class A {
}

import std.algorithm;
import std.array;
struct TemplateInstancier {
    auto instanciateFromResolvedArgs(A a) {
        auto bs = [B(a)];

        static A gladeulfeurah;
        gladeulfeurah = a;
        // XXX: have to put array once again to avoid multiple map.
        string id = bs.map!(
            b => b.apply!(
                function string() { assert(0); },
                delegate string(i) {
                    assert(a is gladeulfeurah, "tagazok");
                    return "";
                }
            )
        ).join;
    }
}

enum Tag {
    Undefined,
    A,
}

struct B {
    A a;
    Tag tag;

    this(A a) {
        tag = Tag.A;
        this.a = a;
    }
}

auto apply(alias undefinedHandler, alias handler)(B b) {
    final switch(b.tag) with(Tag) {
        case Undefined :
            return undefinedHandler();

        case A :
            return handler(b.a);
    }
}

fail.d:
import a;

void main() {
    auto a = new A();
    TemplateInstancier().instanciateFromResolvedArgs(a);
}

Compile via:
dmd -c -offail.o fail.d -m64 -w -debug -gc
dmd -c -ofa.o a.d -m64 -w -debug -gc
gcc -o fail fail.o a.o -m64 -lphobos2 -export-dynamic -ldl

Run via:
./fail

The program assert fail with the message tagazok. The value of the variable a
in the closure is incorrect.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 16 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com



21:21:22 PST ---
I can't get this to even link on Linux, the result is:

a.o:(.tbss+0x0): multiple definition of
`_D1a18TemplateInstancier27instanciateFromResolvedArgsMFC1a1AZv13gladeulfeurahC1a1A'
foo.o:(.tbss+0x0): first defined here
a.o: In function
`_D1a18TemplateInstancier27instanciateFromResolvedArgsMFC1a1AZv':
/home/walter/cbx/mars/a.d:7: multiple definition of
`_D1a18TemplateInstancier27instanciateFromResolvedArgsMFC1a1AZv'
foo.o:/home/walter/cbx/mars/a.d:7: first defined here
collect2: ld returned 1 exit status
--- errorlevel 1

The program compiles and runs without error on Windows.

BTW, is it possible for you to simplify the example code? I find it so
convoluted as to be completely baffling.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 28 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447




22:42:35 PST ---
This gives the multiple definition error on Linux:

------- a.d -----------
struct A { }

void map(alias dg)(A r) { }

struct TTT {
    static auto yyy(A a) {
        map!(b => 0)(a);
    }
}
------- fail.d ---------
import a;

void main() {
    A a;
    TTT.yyy(a);
}
-----------------------


12:11:10 PST ---
https://github.com/D-Programming-Language/dmd/pull/3045

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 29 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447




Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/167b6b7dafd7dede3e71714de195ceff129497df
fix Issue 11447 - Closure provide bogus values

https://github.com/D-Programming-Language/dmd/commit/fcf76cd0979c21cfc7d162164b081d7e181bc046


fix Issue 11447 - Closure provide bogus values

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 30 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447


Walter Bright <bugzilla digitalmars.com> changed:

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


-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 30 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447




Commit pushed to 2.065 at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/1ea66b6b17354a8cce69d1ef6c182e70c748e1e5


fix Issue 11447 - Closure provide bogus values

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 31 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447


deadalnix <deadalnix gmail.com> changed:

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



REOPENING.

Code supplied in comment 2 still fail as follow :

a.o:(.tbss+0x0): définitions multiples de «
_D1a18TemplateInstancier27instanciateFromResolvedArgsMFC1a1AZv13gladeulfeurahC1a1A
»
fail.o:(.tbss+0x0): défini pour la première fois ici
a.o: dans la fonction «
_D1a18TemplateInstancier27instanciateFromResolvedArgsMFC1a1AZv »:
/home/deadalnix/d/tests/a.d:7: définitions multiples de «
_D1a18TemplateInstancier27instanciateFromResolvedArgsMFC1a1AZv »
fail.o:/home/deadalnix/d/tests/a.d:7: défini pour la première fois ici
collect2: error: ld returned 1 exit status

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 08 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447





 REOPENING.
 
 Code supplied in comment 2 still fail as follow :
 
 a.o:(.tbss+0x0): définitions multiples de «
 _D1a18TemplateInstancier27instanciateFromResolvedArgsMFC1a1AZv13gladeulfeurahC1a1A
 »
 fail.o:(.tbss+0x0): défini pour la première fois ici
 a.o: dans la fonction «
 _D1a18TemplateInstancier27instanciateFromResolvedArgsMFC1a1AZv »:
 /home/deadalnix/d/tests/a.d:7: définitions multiples de «
 _D1a18TemplateInstancier27instanciateFromResolvedArgsMFC1a1AZv »
 fail.o:/home/deadalnix/d/tests/a.d:7: défini pour la première fois ici
 collect2: error: ld returned 1 exit status
Do you try it with latest git head (b1aa0cb)? If not, recently fixed bug 11863 might also fix this bug. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 08 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447






 REOPENING.
 
 Code supplied in comment 2 still fail as follow :
 
 a.o:(.tbss+0x0): définitions multiples de «
 _D1a18TemplateInstancier27instanciateFromResolvedArgsMFC1a1AZv13gladeulfeurahC1a1A
 »
 fail.o:(.tbss+0x0): défini pour la première fois ici
 a.o: dans la fonction «
 _D1a18TemplateInstancier27instanciateFromResolvedArgsMFC1a1AZv »:
 /home/deadalnix/d/tests/a.d:7: définitions multiples de «
 _D1a18TemplateInstancier27instanciateFromResolvedArgsMFC1a1AZv »
 fail.o:/home/deadalnix/d/tests/a.d:7: défini pour la première fois ici
 collect2: error: ld returned 1 exit status
Do you try it with latest git head (b1aa0cb)? If not, recently fixed bug 11863 might also fix this bug.
Just tried with the latest git master. Last commit : commit 41ebb59707444b8e2b0b03a77ec45c6856c7dda8 Merge: 67c7551 59ba51e Author: Iain Buclaw <ibuclaw ubuntu.com> Date: Fri Dec 6 15:22:31 2013 -0800 [DDMD] Fix a few ubyte/char mismatches that slipped through Still fail to link with a multiple definition message for symbol _D1a18TemplateInstancier27instanciateFromResolvedArgsMFC1a1AZv13gladeulfeurahC1a1A and _D1a18TemplateInstancier27instanciateFromResolvedArgsMFC1a1AZv -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 09 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447




---

 Just tried with the latest git master. Last commit :
 
 commit 41ebb59707444b8e2b0b03a77ec45c6856c7dda8
 Merge: 67c7551 59ba51e
 Author: Iain Buclaw <ibuclaw ubuntu.com>
 Date:   Fri Dec 6 15:22:31 2013 -0800
 

 
     [DDMD] Fix a few ubyte/char mismatches that slipped through
"Fri Dec 6" !? It's committed at a month ago. I meant that the commit at three days ago. commit 6090f4599b4da0a642796c1d2655a26f0ce99b17 Merge: 044717c 4c846a2 Author: Don Clugston <dclugston googlemail.com> Date: Tue Jan 7 00:09:49 2014 -0800 [REG2.064] Issue 11863 - std.conv.to!string(int/uint, radix) returns incorrect string -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 09 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447


deadalnix <deadalnix gmail.com> changed:

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





 Just tried with the latest git master. Last commit :
 
 commit 41ebb59707444b8e2b0b03a77ec45c6856c7dda8
 Merge: 67c7551 59ba51e
 Author: Iain Buclaw <ibuclaw ubuntu.com>
 Date:   Fri Dec 6 15:22:31 2013 -0800
 

 
     [DDMD] Fix a few ubyte/char mismatches that slipped through
"Fri Dec 6" !? It's committed at a month ago. I meant that the commit at three days ago. commit 6090f4599b4da0a642796c1d2655a26f0ce99b17 Merge: 044717c 4c846a2 Author: Don Clugston <dclugston googlemail.com> Date: Tue Jan 7 00:09:49 2014 -0800 [REG2.064] Issue 11863 - std.conv.to!string(int/uint, radix) returns incorrect string
OK for some reason my git repo was broken and I wasn't pulling. This is fixed. Thanks ! -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 10 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447


deadalnix <deadalnix gmail.com> changed:

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



The bug is back in master. Reopening.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 25 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447




12:58:55 PST ---

 The bug is back in master. Reopening.
1. Which test case? 2. Failing to link, or failing to run? -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 26 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447






 The bug is back in master. Reopening.
1. Which test case? 2. Failing to link, or failing to run?
Code provided in comment 2 compile and link, but the values captured in the closure are bogus. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 26 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447




16:25:09 PST ---


 Code provided in comment 2 compile and link, but the values captured in the
 closure are bogus.
What happens if you try linking it normally, i.e.: dmd -m64 fail.o a.o ?
Never mind, I can repro the failure on Windows with master. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 26 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447




16:41:25 PST ---
Grumble, this is great, 61 source files changed since it worked, and probably
10,000 lines changed.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 26 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447




02:43:04 EET ---
This sounds like a job for D-dot-git! I can find the exact commit that
introduced the regression, I just need: 1) the last commit where it worked, and
2) files/instructions on how to reproduce the problem on Windows.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 26 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447




16:47:39 PST ---
Somewhere between:

commit 11f05b5dad2f5ef22a73dd851db1ec108508e022
Merge: cb5ace9 91a5c8a
Author: Hara Kenji <k.hara.pg+dev gmail.com>
Date:   Thu Jan 16 05:54:22 2014 -0800

and:

commit edc0125846974e34bf153c21f2d5cb40141ff3e1
Merge: 01ca07b 57e1395
Author: Walter Bright <walter walterbright.com>
Date:   Sun Jan 26 12:17:17 2014 -0800

the bug reappeared. Anyone feel like doing a git bisect?

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 26 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447




16:48:30 PST ---
To repro on Windows:

dmd -c fail.d -w -debug -gc
dmd -c a.d -w -debug -gc
dmd fail.obj a.obj
fail

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 26 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447




02:49:32 EET ---
I'm on it!

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 26 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447




16:50:41 PST ---

 I'm on it!
Thank you! You da man! -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 26 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447




03:08:41 EET ---
For me, this bug is reproduced even on 11f05b5dad2f5ef22a73dd851db1ec108508e022

going to try to reproduce it on Linux and remove the Phobos dependency.

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 26 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447




17:25:01 PST ---

 For me, this bug is reproduced even on 11f05b5dad2f5ef22a73dd851db1ec108508e022

 going to try to reproduce it on Linux and remove the Phobos dependency.
Hmm, I was using the Jan 16 phobos for both runs. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 26 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447




03:50:32 EET ---
Found it:

https://github.com/D-Programming-Language/dmd/pull/3107

[REG2.065a] Issue 11931 - Linkers "Symbol Undefined" again with dmd HEAD when
-g specified

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 26 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447




03:57:06 EET ---
5321d36d12dfe0b3c18cdb9755ea6342ebe664b3 is the first bad commit
commit 5321d36d12dfe0b3c18cdb9755ea6342ebe664b3
Author: k-hara <k.hara.pg gmail.com>
Date:   Sat Jan 18 14:42:41 2014 +0900

    fix Issue 11931 - Linkers "Symbol Undefined" again with dmd HEAD when -g
specified

    Also add test case for issue 7595.

:040000 040000 831cbb65162bb4de49c865cbb4c497165e1df18b
bf75df6e2964a3a1666ead1ca19f9c723afb4cf8 M      src
:040000 040000 d37c2c62637a6d3b1c2b60455b46a0cd5e7b4385
2dfd0ee0660e40585c6960235f57d1103c952a7f M      test
bisect run success

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 26 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull, wrong-code
           Platform|x86_64                      |All
         OS/Version|Linux                       |All



---
https://github.com/D-Programming-Language/dmd/pull/3162

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 26 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447


Walter Bright <bugzilla digitalmars.com> changed:

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



20:27:46 PST ---
Great work, guys!

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 26 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447





 Great work, guys!
+1, that is awesome ! -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 27 2014
prev sibling next sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447




Commit pushed to 2.065 at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/7ac4d39c715d6186c3d4a8008f488e36846154f7


[REG2.065a] Issue 11447 - Closure provide bogus values

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 27 2014
prev sibling parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11447




Commit pushed to 2.065 at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/3e8509a4f5411f300abd57b1f226bbf705dff3cc


[REG2.065a] Issue 11447 - Closure provide bogus values

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 27 2014