www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3041] New: Array slices can be compared to their element type: bad codegen or ICE

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

           Summary: Array slices can be compared to their element type:
                    bad codegen or ICE
           Product: D
           Version: 1.045
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: accepts-invalid, ice-on-invalid-code, wrong-code
          Severity: major
          Priority: P3
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: matti.niemenmaa+dbugzilla iki.fi


The following invalid code is accepted by DMD 1.045:

void main() {
    int[1] a = 1;
    int b = 1;
    assert (a[] == b);
}

The assertion fails, meaning that some nonsense code has been generated.
According to the spec the above is invalid: == isn't an array operation. Other
comparison operators like < and >= are also incorrectly accepted.

The following variation gives "Internal error: ../ztc/cgcod.c 1554":

void main() {
    int[] a = [1];
    int b = 1;
    assert (a[] == b);
}

If the slice is removed from the assertion, making it read just "a == b",
neither example compiles, as expected:

arst.d(4): Error: incompatible types for ((a) == (b)): 'int[1u]' and 'int'
arst.d(4): Error: incompatible types for ((a) == (b)): 'int[]' and 'int'

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


Don <clugdbug yahoo.com.au> changed:

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






Root cause: CmpExp::toElem() and EqualExp::toElem() have a special case
for a[] == b[], but not for a[]==b.

--- e2ir.c    (revision 27)
+++ e2ir.c    (working copy)
   -2191,6 +2191,14   
     e = el_bin(eop, TYint, e, el_long(TYint, 0));
     el_setLoc(e,loc);
     }
+    else if ((int)eop > 1 &&
+         (t1->ty == Tarray || t1->ty == Tsarray) ||
+         (t2->ty == Tarray || t2->ty == Tsarray))
+    {
+        error("Invalid array comparison operation");
+        e = toElemBin(irs, eop);
+        return e;
+    }
     else
     {
     if ((int)eop <= 1)
   -2285,6 +2293,14   
         e = el_bin(OPxor, TYint, e, el_long(TYint, 1));
     el_setLoc(e,loc);
     }
+    else if ((t1->ty == Tarray || t1->ty == Tsarray) ||
+         (t2->ty == Tarray || t2->ty == Tsarray))
+    {
+    error("Invalid array equality operation");
+    e = toElemBin(irs, eop);
+    return e;
+
+    }
     else
     e = toElemBin(irs, eop);
     return e;
*/

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




01:20:22 PDT ---
The error detection really needs to go in the front end, in
EqualExp::semantic(), etc. I'll fix.

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


Walter Bright <bugzilla digitalmars.com> changed:

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



13:45:26 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