www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2048] New: Code causes DMD to crash

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

           Summary: Code causes DMD to crash
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: 2korden gmail.com


The following code crashes both DMD1 and DMD2:

File crash.d:
struct Number
{
    public int value;

    static Number opCall(int value)
    {
        Number n = void;
        n.value = value;
        return n;
    }
}

class Crash
{
    Number number = Number(0);
}

// end of file

replacing Number n = void; with Number n; resolves issue.


-- 
Apr 27 2008
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2048


2korden gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-valid-code
            Summary|Code causes DMD to crash    |DMD crash on CTFE that
                   |                            |involves assigning to member
                   |                            |variables of void-
                   |                            |initialized struct




------- Comment #1 from 2korden gmail.com  2008-07-18 04:22 -------
Is this code a correct D in the first place?

struct Number
{
    static Number opCall()
    {
        Number n = void;
        return n;
    }
}

class Crash
{
    Number number = Number();
}

crash.d(6): Error: variable n is used before initialization
crash.d(12): Error: cannot evaluate opCall() at compile time

If it isn't and variable can't use void initializer for expression to work in
compile time, then the fix is trivial.

But I think that it should work. IIRC, if you initialize a variable with void
it means "initialize with anything, I don't care" so that compiler could simply
increase stack pointer instead of putting some meaningful values to stack for a
variable to initialize, or do some other optimization. If it is, then a void
initializer can be ignored for CTFE and a variable can be initialized with a
zero- or default initializer, since both belongs to/are subset of "any
initializer". Moreover CTFE should have determinative behavior.

Adding something like this:
if ((v->value == NULL) && (v->init->isVoidInitializer()) {
        v->value = v->type->defaultInit();
}
solved the problem and compiled both samples for me.


-- 
Jul 18 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2048





------- Comment #2 from clugdbug yahoo.com.au  2009-04-24 05:25 -------
Created an attachment (id=337)
 --> (http://d.puremagic.com/issues/attachment.cgi?id=337&action=view)
Patch against DMD2.029

Koroskin's patch


-- 
Apr 24 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2048


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |clugdbug yahoo.com.au
         Resolution|                            |FIXED




--- Comment #3 from Don <clugdbug yahoo.com.au>  2009-05-14 07:01:42 PDT ---
Fixed DMD2.030 and 1.045

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 14 2009