www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3192] New: asm in a anonymous delegate crash the compiler

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

           Summary: asm in a anonymous delegate crash the compiler
           Product: D
           Version: 1.046
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: blocker
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: lifc0 yahoo.com.cn


below lines crash dmd 1.046/2.031 on linux and window platfrom:

void func (void delegate () callback) {
    callback();
}

void main () {
    func(() { asm{ int 3; }; });
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 19 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3192


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au
            Summary|asm in a anonymous delegate |Segfault(iasm.c) asm in a
                   |crash the compiler          |anonymous delegate
           Severity|blocker                     |major





Reduced test case:

void delegate () foo = (){ asm{ int 3; }};

This is segfaulting in iasm.c (line 4269 in DMD2).
if( sc->func->type->nextOf()->isScalar()) // segfaults here: nextOf() is null.

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


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch





This patch is enough to fix the segfault, and allow the code to compile. I'm
not sure if it's correct that nextOf() is null, though -- there may be a deeper
problem here.

iasm.c line 4269. (in Statement *AsmStatement::semantic(Scope *sc)):

    asmstate.bReturnax = 1;
-    if (sc->func->type->nextOf()->isscalar())
+    if (sc->func->type->nextOf() && sc->func->type->nextOf()->isscalar())
    asmstate.bReturnax = 0;

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com





02:24:23 PDT ---
For inferring function return type, the nextOf() is null. That would be a
problem here, but we never use bReturnax anyway, so just #if out the code.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 20 2009
prev sibling next sibling parent reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3192







 For inferring function return type, the nextOf() is null.
It'd be great if you could put that in a comment in the definition of nextOf(). I'd never been sure when it's supposed to be non-null, it's one of the least obvious things in the code. Should it become non-null in a later semantic pass? Also a comment about the cto, ito, sto members of type would be really useful. When should they be non-null? In a great many of the compiler bugs I've looked at, they're null, but I've not been sure whether the bug is that they're null, or that other code is not dealing with the case that they're null. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 20 2009
parent Walter Bright <newshound1 digitalmars.com> writes:
I'll put some comments in.
Jul 20 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3192


Walter Bright <bugzilla digitalmars.com> changed:

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





13:27:02 PDT ---
Fixed dmd 1.047 and 2.032

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