www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1586] New: DMD and GDC segfaults on incomplete code segment.

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

           Summary: DMD and GDC segfaults on incomplete code segment.
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: hoytak cs.ubc.ca


Hello,

A typo revealed a way to make the compiler segfault.  Trying to compile the
following incomplete code segment as a complete module causes the official D
compiler (versions 1.022 and 2.005) and GDC 0.24 to segfault.

////////////
module badcode;

void myFunc()
{
   auto func = &NotHere!(1).Bar!(k);  // NotHere is not defined.
}

/////////////

Thanks!
--Hoyt


-- 
Oct 16 2007
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1586






Added to DStress as
http://dstress.kuehne.cn/nocompile/t/template_66_A.d
http://dstress.kuehne.cn/nocompile/t/template_66_B.d
http://dstress.kuehne.cn/nocompile/t/template_66_C.d
http://dstress.kuehne.cn/nocompile/t/template_66_D.d
http://dstress.kuehne.cn/nocompile/t/template_66_E.d


-- 
Oct 19 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1586






The segv is in this code:

Expression *DotTemplateInstanceExp::semantic(Scope *sc)
...
    if (!s2)
    {   error("template identifier %s is not a member of %s %s", id->toChars(),
s->kind(), s->ident ? s->ident->toChars() : "(null)");
        goto Lerr;
    }
...

s->ident is null, so s->ident->toChars() is invalid.  I added the ?: expression
to validate that, and here's the resulting error message: 
/home/braddr/sandbox/d/bugs/bug1586.d:5: template instance identifier 'NotHere'
is not defined
/home/braddr/sandbox/d/bugs/bug1586.d:5: Error: template identifier Bar is not
a member of template instance (null)

My fix is wrong, but hopefully this will save Walter a few minutes of narrowing
down.


-- 
Oct 28 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1586






While I enjoy another fix:

    if (!s2)
    {
         if(s->ident)   
              error("template identifier %s is not a member of %s %s",
id->toChars(),
s->kind(), s->ident->toChars() : "(null)");
        goto Lerr;
    }

Since the Template Instance is unknown so this error message is useless.


-- 
Dec 13 2007
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1586






Fixed in DMD2.028; not yet in D1.


-- 
May 07 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1586


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au





Fixed DMD2.028 and 1.045.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 14 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1586


Don <clugdbug yahoo.com.au> changed:

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




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