www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2829] New: aborted when accessing out of bounds element in a static array constant initialized through struct literal

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

           Summary: aborted when accessing out of bounds element in a static
                    array constant initialized through struct literal
           Product: D
           Version: 1.043
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Keywords: ice-on-invalid-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: kamm-removethis incasoftware.de


struct S { int[3] i; }
const S s = S(5);
const int i = s.i[10];

generates

int[3u] 0x82ee4e0
dmd: expression.c:1352: virtual dinteger_t IntegerExp::toInteger(): Assertion
`0' failed.
Aborted


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


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch, rejects-valid
            Summary|ICE(expression.c) accessing |ICE(expression.c) static
                   |out of bounds element in a  |array block-initialized in
                   |static array constant       |struct literal
                   |initialized through struct  |
                   |literal                     |
         OS/Version|Linux                       |All




--- Comment #1 from Don <clugdbug yahoo.com.au>  2009-06-02 16:25:14 PDT ---
Title was: ICE(expression.c) accessing out of bounds element in a static array
constant initialized through struct literal
Changed since it is more general. Applies to D2 as well as D1.

-- ANALYSIS --
This is crashing in constfold.c, line 1218, crashing while doing e1->toChars()
while printing the error message. But there are also rejects-valid bugs with
the
same root cause: block assignment of arrays is buggy.
The root cause is expression.c, StructLiteralExp::getField().
In the line e->type=type is incorrect if e->type is of type K, and 'type' 
is a static array of type K.
PATCH: in such cases, create and populate an array literal.

--- expression.c    (revision 27)
+++ expression.c    (working copy)
   -3236,7 +3236,18   
     if (e)
     {
         e = e->copy();
+    if (e->type != type && type->ty == Tsarray)
+    {    TypeSArray *tsa = (TypeSArray *)type;
+            uinteger_t length = tsa->dim->toInteger();
+            Expressions * z = new Expressions;
+            z->setDim(length);
+            for (int q=0; q<length; ++q) z->data[q] = e->copy();
+            ArrayLiteralExp * ac = new ArrayLiteralExp(loc, z);
+            ac -> type = type;
+            e = ac;
+        } else {
         e->type = type;
+        }
     }
     }
     return e;

== TEST CASE 2 -- ICE(expression.c) == For D2, change 'enum' to 'const' for D1.
struct S { int i[3]; }
enum S s = S(8);
int * p  = & s.i;

// Test case 3 -- rejects-valid
struct Q { double i[3]; }
enum Q q = Q(8.0*real.min);
const  x = q.i[2];

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


Walter Bright <bugzilla digitalmars.com> changed:

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


--- Comment #2 from Walter Bright <bugzilla digitalmars.com> 2009-10-13
13:44:51 PDT ---
Fixed dmd 1.049 and 2.034

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