D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6506 - OS X: wrong value is passed to simple argument along with a delegate with -O
Summary: OS X: wrong value is passed to simple argument along with a delegate with -O
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Mac OS X
: P2 major
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2011-08-16 10:58 UTC by kennytm
Modified: 2011-08-16 18:50 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description kennytm 2011-08-16 10:58:09 UTC
----------------------------
void enforce6506(bool condition, lazy int m) {
    assert(!condition);
}
void toImpl6506(int value) {
    enforce6506(value >= 0, 4);
}
void bug6506() {
    toImpl6506(-112345);
}

void main() { bug6506(); }
----------------------------
$ dmd -unittest -release -O z.d
$ ./z
core.exception.AssertError@z(2): Assertion failure
...
----------------------------

The bug _does_not_ appear when:
 - one of '-unittest', '-release', and '-O' doesn't exist.
 - the type of 'condition' is not 'bool', 'u?(byte|short|int)' and '[wd]?char'.
 - the 'lazy' argument doesn't exist.

This bug is preventing OS X from passing Phobos' unit test in the release build after fixing bug 6377. See also https://github.com/D-Programming-Language/phobos/commit/994d76fe.
Comment 1 kennytm 2011-08-16 11:50:31 UTC
Correction:

1. Only -O is needed.
2. It's not 'lazy' causing the bug, but passing a nested delegate.

-------------------------------
void enforce6506b(bool condition, void delegate() m) {
    assert(!condition);
}
void toImpl6506b(int value) {
    void f(){}
    enforce6506b(value >= 0, &f);
}
void bug6506b() {
    toImpl6506b(-112345);
}

void main() { bug6506b(); }
-------------------------------
$ dmd -O z.d
$ ./z
core.exception.AssertError@z(2): Assertion failure
...
-------------------------------
Comment 2 Walter Bright 2011-08-16 18:50:20 UTC
The bug is actually there on all platforms (it's a scheduler problem), it just fails in a way that doesn't show on the others.

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

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