Thread overview
[Issue 3737] New: SEG-V at expression.c:6255 from bad code
Jan 23, 2010
BCS
Jan 23, 2010
BCS
Jan 25, 2010
Don
Jan 25, 2010
BCS
Jan 25, 2010
Don
Jan 25, 2010
Don
[Issue 3737] SEG-V at expression.c:6255 from bad opDispatch
Jan 26, 2010
Don
Feb 05, 2010
Walter Bright
Feb 05, 2010
Kosmonaut
Mar 09, 2010
Walter Bright
January 23, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3737

           Summary: SEG-V at expression.c:6255 from bad code
           Product: D
           Version: 2.039
          Platform: Other
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: shro8822@vandals.uidaho.edu


--- Comment #0 from BCS <shro8822@vandals.uidaho.edu> 2010-01-23 13:03:57 PST ---
Created an attachment (id=554)
patch to convert seg-v to assert

I'm getting a seg-v (not an assert) at expression.c:6255 from some bad template
code.

this is the test case:

http://www.dsource.org/projects/scrapple/browser/trunk/units/si2.d?rev=689

compile with "-unittest -version=BUG" to get error
compile with "-unittest" to get correct result.

attached is a patch that converts the seg-v to an assert.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 23, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3737



--- Comment #1 from BCS <shro8822@vandals.uidaho.edu> 2010-01-23 13:05:00 PST ---
I forgot to mention; I tried to cut down the test case and it quit erroring.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 25, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3737


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-invalid-code
                 CC|                            |clugdbug@yahoo.com.au


--- Comment #2 from Don <clugdbug@yahoo.com.au> 2010-01-25 04:21:29 PST ---
I can't reproduce the segfault. When compiling si2, I just get this:
------
si2.d(155): Error: Cannot interpret
SIB!(__T5BatchVi1Vi1Vi0Vi1Vi0Vi1Vi0Vi1Vi0Vi1
Z,real) at compile time
si2.d(155): Error: Cannot interpret
SIB!(__T5BatchVi1Vi1Vi0Vi1Vi0Vi1Vi0Vi1Vi0Vi1
Z,real) at compile time
si2.d(155): Error: template instance
'Batch!(LengthN,1,MassN,1,TimeN,1,TempN,1,C
urrentN,1)' is not a variable
si2.d(155): Error: no property 'LenD' for type 'int'

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 25, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3737



--- Comment #3 from BCS <shro8822@vandals.uidaho.edu> 2010-01-25 10:32:24 PST ---
What version of DMD? I got it with 2.039 on both windows and linux. Might it already be fixed in SVN?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 25, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3737



--- Comment #4 from Don <clugdbug@yahoo.com.au> 2010-01-25 12:22:35 PST ---
(In reply to comment #3)
> What version of DMD? I got it with 2.039 on both windows and linux. Might it already be fixed in SVN?

I can reproduce it now. I think I had the wrong rational.d.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 25, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3737



--- Comment #5 from Don <clugdbug@yahoo.com.au> 2010-01-25 13:01:07 PST ---
Reduced test case. Something to do with opDispatch.
======================
int crayon;

struct SIB(alias junk)
{
    template Alike(V) {
        enum bool Alike = Q == V.garbage;
    }
    void opDispatch(string s)() {
        static assert(Alike!(SIB!(crayon)));
    }
}

void main() {
      SIB!(SIB!(crayon).E)(3.0);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 26, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3737


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
            Summary|SEG-V at expression.c:6255  |SEG-V at expression.c:6255
                   |from bad code               |from bad opDispatch


--- Comment #6 from Don <clugdbug@yahoo.com.au> 2010-01-26 00:06:30 PST ---
Cause: If global.errors && !global.gag, TemplateInstance::semantic doesn't set 'inst'. So this is a possible patch (not recommended) inside template.c:

    {
    if (!global.gag)
    {
        /* Trying to soldier on rarely generates useful messages
         * at this point.
         */
        fatal();
    }
+    inst = this; // error recovery
    return;
    }
===
But, on the other hand, most other functions in expression.c only run
ti->semantic() if there are global.errors.

So this patch to expression.c line 6252 may be better:

Expression *DotTemplateInstanceExp::semantic(Scope *sc)
{
#if LOGSEMANTIC
    printf("DotTemplateInstanceExp::semantic('%s')\n", toChars());
#endif
    Expression *eleft;
    Expression *e = new DotIdExp(loc, e1, ti->name);
L1:
    e = e->semantic(sc);

    if (e->op == TOKdottd)
    {
+    if (global.errors) return new ErrorExp();
    DotTemplateExp *dte = (DotTemplateExp *)e;
    TemplateDeclaration *td = dte->td;

The same problem occurs in mtype.c, line 6613, 7101, inside ::dotExp(), for
structs and classes, and they should probably have the same fix.
(they shouldn't be running ti->semantic() if there are global errors).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 05, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3737


Walter Bright <bugzilla@digitalmars.com> changed:

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


--- Comment #7 from Walter Bright <bugzilla@digitalmars.com> 2010-02-04 21:10:21 PST ---
changeset 367

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
February 05, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3737


Kosmonaut <Kosmonaut@tempinbox.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Kosmonaut@tempinbox.com


--- Comment #8 from Kosmonaut <Kosmonaut@tempinbox.com> 2010-02-04 22:48:30 PST ---
(In reply to comment #7)
> changeset 367

http://www.dsource.org/projects/dmd/changeset/367

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
March 09, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3737


Walter Bright <bugzilla@digitalmars.com> changed:

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


--- Comment #9 from Walter Bright <bugzilla@digitalmars.com> 2010-03-08 22:22:36 PST ---
Fixed dmd 1.057 and 2.041

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