www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1984] New: Assertion in dmd

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

           Summary: Assertion in dmd
           Product: D
           Version: 2.012
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: bartosz relisoft.com


Assertion failure: 'e1->type' on line 1198 in file 'constfold.c'

when compiling this test:

import std.string;
import std.stdio;

string genClass (invariant bool [string] set)
{
        string result;
        foreach (x; set.keys)
        {
                result ~= x ~ " ";
        }
        return result;
}

void main ()
{
        invariant bool [string] map = [ "foo":true, "bar":true ];
        string res = mixin (genClass (map));
        writefln (res);
}


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


smjg iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg iname.com
           Keywords|                            |ice-on-valid-code
            Summary|Assertion in dmd            |Assertion failure: 'e1-
                   |                            |>type' on line 1198 in file
                   |                            |'constfold.c'




------- Comment #1 from smjg iname.com  2008-11-20 21:18 -------
An even more serious problem: the AA initialisation throws an AV at runtime.


-- 
Nov 20 2008
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=1984





------- Comment #2 from clugdbug yahoo.com.au  2009-05-04 07:11 -------
Reduced test case shows it's a problem with CTFE and AA literals.

immutable bool [int] map = [ 4:true, 5:true ];
int foo () {
    foreach (x; map.keys) {}
    return 3;
}

static int x = foo();


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


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |clugdbug yahoo.com.au
            Version|2.012                       |1.037




--- Comment #3 from Don <clugdbug yahoo.com.au>  2009-05-13 11:49:03 PDT ---

Here are two more extreme versions of the same bug. They segfault even on D1.
// TEST CASE 1: // Segfault D1 and D2.
int[] map = ([ 4:true, 5:true ]).keys;
// TEST CASE 2:
bool[] foo2 = ([ 4:true, 5:true ]).values;


PATCH against DMD2.029
PATCH (interpret.c)
This is crashing because interpret_aakeys() and interpret_aavalues() aren't
setting the type of the array literal which they are creating.
This patch fixes both the segfaults and the original bug.

Note, however, that the original bug report generates an error, because AA
literals cannot be used at runtime. With this patch, the CTFE part of it works
fine.

--- interpret.c    (revision 26)
+++ interpret.c    (working copy)
   -2291,6 +2295,8   
     return NULL;
     AssocArrayLiteralExp *aae = (AssocArrayLiteralExp *)earg;
     Expression *e = new ArrayLiteralExp(aae->loc, aae->keys);
+    Type *elemType = ((TypeAArray *)aae->type)->index;
+    e->type = new TypeSArray(elemType, ArrayLength(elemType, e));
     return e;
 }

   -2307,6 +2313,8   
     return NULL;
     AssocArrayLiteralExp *aae = (AssocArrayLiteralExp *)earg;
     Expression *e = new ArrayLiteralExp(aae->loc, aae->values);
+    Type *elemType = ((TypeAArray *)aae->type)->next;
+    e->type = new TypeSArray(elemType, ArrayLength(elemType, e));
     //printf("result is %s\n", e->toChars());
     return e;
 }

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


Walter Bright <bugzilla digitalmars.com> changed:

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




--- Comment #4 from Walter Bright <bugzilla digitalmars.com>  2009-07-09
02:46:22 PDT ---
Fixed dmd 1.046 and 2.031

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