[Issue 9720] New: OSX wrong code with -o "Illegal instruction"
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Mar 14 07:12:21 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9720
Summary: OSX wrong code with -o "Illegal instruction"
Product: D
Version: D2
Platform: All
OS/Version: Mac OS X
Status: NEW
Severity: blocker
Priority: P2
Component: DMD
AssignedTo: nobody at puremagic.com
ReportedBy: monarchdodra at gmail.com
--- Comment #0 from monarchdodra at gmail.com 2013-03-14 07:12:20 PDT ---
Investigated from:
https://github.com/D-Programming-Language/phobos/pull/878
http://d.puremagic.com/test-results/pull-history.ghtml?projectid=1&repoid=3&pullid=878
Happens with OSX, when compile with -O.
Below a reduced test case:
//----
import std.stdio;
//Simplified RefCounted
struct MyRef(T)
{
private struct Impl
{
T _payload;
size_t _count;
}
Impl* _store;
this(int i)
{
_store = new Impl;
_store._payload = T.init;
_store._count = 1;
}
~this()
{
if (!_store) return;
writeln("d: ", _store._count); //Comment me
--_store._count;
}
}
//Extracted from Array
struct Payload
{
size_t _capacity; //Comment me
int[] _pay; //Comment me
size_t insertBack(Stuff)(Stuff /+stuff+/)
{
immutable newLen = _pay.length + 3;
_pay.length = newLen;
_pay = _pay[0 .. newLen]; //Comment me
return 3;
}
}
alias Data = MyRef!Payload;
unittest
{
auto a = Data(1);
auto b = Data(1);
writeln(__LINE__);
a._store._payload.insertBack(1); //Passes
writeln(__LINE__);
a._store._payload.insertBack(b); //Fails
writeln(__LINE__);
}
//----
rdmd -w -d -property -O --main -unittest test2.d
47
49
d: 1
Illegal instruction
//---
I was not able to simplify much more, as the compile-time behavior is non
deterministic: EG: removing an unused variable such as "capacity" is enough to
make the problem "disappear" (or at least, unobservable).
AFAIK, this code contains nothing unsafe, and the only requirement to reproduce
is as simple as "pass by value something with a destructor"... (!)
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list