www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3496] New: ICE ..\ztc\cgelem.c 3387

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

           Summary: ICE ..\ztc\cgelem.c 3387
           Product: D
           Version: unspecified
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: dsimcha yahoo.com


--- Comment #0 from David Simcha <dsimcha yahoo.com> 2009-11-11 09:51:33 PST ---
struct Node {
    size_t _left;

    Node* left() {
        return cast(Node*) (_left & 1);
    }

    bool useLeft() {
        return left is null;
    }
}

Result:

Internal error: ..\ztc\cgelem.c 3387

This one is really hard to reproduce.  If you change this test program in even
very small ways, it's no longer reproduced.

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


Don <clugdbug yahoo.com.au> changed:

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


--- Comment #1 from Don <clugdbug yahoo.com.au> 2009-11-12 07:17:10 PST ---
I can't reproduce this (on Windows) with either D2 or D1. I tried several
compiler versions, it compiled correctly in all cases.

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



--- Comment #2 from David Simcha <dsimcha yahoo.com> 2009-11-13 08:02:26 PST ---
Didn't realize it at the time, but I've looked into this further.  It only
happens when you compile w/ -O -inline.

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


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unspecified                 |1.00
            Summary|ICE ..\ztc\cgelem.c 3387    |ICE(cgelem.c, optimizer
                   |                            |bug) cast(void *)(x&1)==
                   |                            |null.


--- Comment #3 from Don <clugdbug yahoo.com.au> 2009-11-13 12:42:02 PST ---
Reduced test case. Compile with -O (-inline not required). Not a regression;
fails on DMD0.165.

bool foo() {
    int x;
    return cast(void*) (x & 1) == null;
}

Internal error: ztc\cgelem.c 3387

Really peculiar thing is that replacing & with | or ^ makes the bug disappear.

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


Don <clugdbug yahoo.com.au> changed:

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


--- Comment #4 from Don <clugdbug yahoo.com.au> 2009-11-13 13:17:00 PST ---
This assert is actually completely harmless. It's part of a check for if the
equality comparison can be reduced to a single byte comparison. This can happen
if it's a pointer with all the high bits clear, which includes null. Here are 3
cases which trigger the same bug.

bool foo() 
{
    int x;
//  return cast(void*) (x & 1) == null;   // Case 1
//  return cast(void*) (x & 1) == cast(void *)(2);  // Case 2
    return cast(bool function()) (x & 1) == null;    // Case 3
}


================
PATCH:

cgelem.c, line 3387.
    /* Try to convert to byte/word comparison for ((x & c)==d)
       when mask c essentially casts x to a smaller type
     */
    if (OPTIMIZER &&
        e1->Eoper == OPand &&
        e1->E2->Eoper == OPconst &&
        (sz = tysize(e2->Ety)) > CHARSIZE)
    {   int op;

-        assert(tyintegral(e2->Ety));        
+        assert(tyintegral(e2->Ety) || (e2->Ety == TYnptr));        
#if TX86        /* ending up with byte ops in A regs */
        if (!(el_tolong(e2) & ~CHARMASK) &&
        !(el_tolong(e1->E2) & ~CHARMASK)
           )
        {

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


Leandro Lucarella <llucax gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |llucax gmail.com


--- Comment #5 from Leandro Lucarella <llucax gmail.com> 2009-11-23 06:48:08
PST ---
SVN commit: http://www.dsource.org/projects/dmd/changeset/267

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


David Simcha <dsimcha yahoo.com> changed:

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


--- Comment #6 from David Simcha <dsimcha yahoo.com> 2009-12-05 18:33:06 PST ---
Fixed 2.037.

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


Walter Bright <bugzilla digitalmars.com> changed:

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


--- Comment #7 from Walter Bright <bugzilla digitalmars.com> 2009-12-06
00:47:30 PST ---
Fixed dmd 1.053 and 2.037

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