D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 8526 - DMD 2.060 regression: anonymous delegate call in foreach loop
Summary: DMD 2.060 regression: anonymous delegate call in foreach loop
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 regression
Assignee: No Owner
URL:
Keywords: pull, wrong-code
: 8775 8974 (view as issue list)
Depends on:
Blocks:
 
Reported: 2012-08-09 00:34 UTC by Vladimir Panteleev
Modified: 2012-11-09 05:48 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Vladimir Panteleev 2012-08-09 00:34:53 UTC
void call(void delegate() callback)
{
	callback();
}

void f(int j, int i)
{
}

void main()
{
	foreach (int i, j; [0])
		call({
			f(j, i);
		});
}

Works on 2.059, segfaults on 2.060. Tested on Win32 and Linux/64.
Comment 1 Damian Ziemba 2012-09-05 01:52:43 UTC
Works with DMD 1.075
Looks like it is D2 only.

DMD2.060 fails both with m32/m64, on Linux and FreeBSD


Current DMD2 trunk still has this bug.
Comment 2 Kenji Hara 2012-11-08 19:43:00 UTC
*** Issue 8775 has been marked as a duplicate of this issue. ***
Comment 3 Kenji Hara 2012-11-08 19:45:42 UTC
From bug 8775, foreach range statement has same bug.

void call(void delegate() dg) { dg(); }
void main()
{
    foreach (i, j; [0])
    {
        call({
            assert(i == 0); // fails, i is corrupted
        });
    }

    foreach (n; 0..1)
    {
        call({
            assert(n == 0); // fails, n is corrupted
        });
    }
}
Comment 4 Kenji Hara 2012-11-08 21:15:15 UTC
*** Issue 8974 has been marked as a duplicate of this issue. ***
Comment 6 github-bugzilla 2012-11-09 04:15:57 UTC
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/251a8bb0ede5e45bf5f41b60554a2962261516ff
fix Issue 8526 - DMD 2.060 regression: anonymous delegate call in foreach loop

This regression has occured from the commit:
https://github.com/D-Programming-Language/dmd/commit/38a0a5141a3455395e8b9571a57bf85ed698c6b3

But the root cause is a bug in glue layer. When an internal ref variable is marked as closure var, the glue layer had generated incorrect code for that.

https://github.com/D-Programming-Language/dmd/commit/8fc3e4b59bf5786accee257d301ca8de8cf8a277
Merge pull request #1272 from 9rnsr/fix8526

Issue 8526 & 6141 - DMD 2.060 regression: anonymous delegate call in foreach loop