[Issue 3496] ICE(cgelem.c, optimizer bug) cast(void *)(x&1)== null.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Nov 13 13:17:01 PST 2009


http://d.puremagic.com/issues/show_bug.cgi?id=3496


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

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


--- Comment #4 from Don <clugdbug at 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: -------


More information about the Digitalmars-d-bugs mailing list