[Issue 3736] corrupted struct returned by function with optimizations (-O)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Feb 8 21:02:15 PST 2010


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


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

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


--- Comment #3 from Don <clugdbug at yahoo.com.au> 2010-02-08 21:02:14 PST ---
This seems to be a problem with transformations which copy the type 'Ety'
without
also copying the size 'Enumbytes', but you need the struct size to be retained.
when the struct size is zero, blocks get dropped and bad codegen results.
This particular bug is fixed by adding:
in optelem(), cgelem.c line 4376 (this is called with op==OPcond).

  if (!OTrtol(op) && op != OPparam && op != OPcolon && op != OPcolon2 &&
          e1->Eoper == OPcomma)
      {    // Convert ((a,b) op c) to (a,(b op c))
        e1->Ety = e->Ety;
+        e1->Enumbytes = e->Enumbytes;
        e->E1 = e1->E2;
        e1->E2 = e;
        e = e1;
        goto beg;
      }      

blockopt.c, brcombine() line 755:

            if (EOP(b3->Belem))
                continue;
            ty = (bc2 == BCretexp) ? b2->Belem->Ety : TYvoid;
            e = el_bin(OPcolon2,ty,b2->Belem,b3->Belem);
            b->Belem = el_bin(OPcond,ty,b->Belem,e);
            }
+            b->Belem->Enumbytes = b2->Belem->Enumbytes;
            b->BC = bc2;


A dozen lines further down the same function are two other calls to 
el_bin(OPcond,...) or el_bin(OPcolon2,...) in brcombine in blockopt.c.

So I suspect line 797 should also be added:

                e = el_bin(OPcolon2,b2->Belem->Ety,
                    b2->Belem,b3->Belem);
                e = el_bin(OPcond,e->Ety,b->Belem,e);
+                e->Enumbytes=b2->Belem->Enumbytes;
                }

But this is just speculation, I don't have a test case which fails there.
There are no other instances of el_bin(OPcond,...) or el_bin(OPcolon2,...)
anywhere else in the backend.
I suspect there are other cases in the backend where types are transferred
but Enumbytes is lost. (there are several in el_comma in cgelem.c).
But mostly this probably just results in lost optimisation opportunities.

-- 
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