[Issue 3115] and = generate wrong code

2015-06-08 Thread via Digitalmars-d-bugs
https://issues.dlang.org/show_bug.cgi?id=3115

Andrei Alexandrescu and...@erdani.com changed:

   What|Removed |Added

Version|2.030   |D2

--


[Issue 3115] and = generate wrong code

2009-12-06 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3115


Walter Bright bugzi...@digitalmars.com changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 CC||bugzi...@digitalmars.com
 Resolution||FIXED


--- Comment #4 from Walter Bright bugzi...@digitalmars.com 2009-12-06 
00:45:54 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: ---


[Issue 3115] and = generate wrong code

2009-11-23 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3115


Leandro Lucarella llu...@gmail.com changed:

   What|Removed |Added

 CC||llu...@gmail.com


--- Comment #3 from Leandro Lucarella llu...@gmail.com 2009-11-23 06:48:52 
PST ---
SVN commit: http://www.dsource.org/projects/dmd/changeset/266

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


[Issue 3115] and = generate wrong code

2009-11-19 Thread d-bugmail
http://d.puremagic.com/issues/show_bug.cgi?id=3115


Don clugd...@yahoo.com.au changed:

   What|Removed |Added

   Keywords||patch
Summary|Illegal optimization to | and = generate wrong
   |unsigned right shift (only  |code
   |array)  |


--- Comment #2 from Don clugd...@yahoo.com.au 2009-11-19 01:36:12 PST ---
This is happening because the backend doesn't constant-fold  correctly.
Consequently, there's incorrect code in a few places because of this.
Sometimes OPshr means , sometimes it means . The patch below changes it so
that OPshr always means . OPashr means  in the case where the value is
signed. The code in evalu8.c is the most important.

This patch may cause problems for DMC. Some of these changes might need to be
inside #if MARS/#endif blocks.

Some test cases: (test with both dmd bug.d and dmd -O bug.d).

long bar() {
return -1L;
}

void main()
{
   long[1] b = void;
   b[0]= bar();

   assert((b[0]2) == 0x3FFFL);
   assert((b[0]2) == 0xL);

   b[0] = -1L;
   assert((b[0]2) == 0x3FFFL);
   assert((b[0]2) == 0xL);

   b[0] = -1L;
   b[0] = 2;
   assert( (b[0]) == 0x3FFFL);
   b[0] = -1L;
   b[0] = 2;
   assert( (b[0]) == 0xL);
}




PATCH:

Index: backend/cod2.c
===
--- backend/cod2.c(revision 252)
+++ backend/cod2.c(working copy)
@@ -1847,8 +1847,8 @@
   oper = e-Eoper;

   // Do this until the rest of the compiler does OPshr/OPashr correctly
-  if (oper == OPshr)
-oper = (uns) ? OPshr : OPashr;
+//  if (oper == OPshr)
+//oper = (uns) ? OPshr : OPashr;

   switch (oper)
   {case OPshl:
Index: backend/cod4.c
===
--- backend/cod4.c(revision 252)
+++ backend/cod4.c(working copy)
@@ -1367,10 +1367,9 @@
 *pretregs |= ALLREGS;

   // Do this until the rest of the compiler does OPshr/OPashr correctly
-  if (oper == OPshrass)
-oper = (uns) ? OPshrass : OPashrass;
+//  if (oper == OPshrass)
+//oper = (uns) ? OPshrass : OPashrass;

-
   // Select opcodes. op2 is used for msw for long shifts.

   switch (oper)
Index: backend/evalu8.c
===
--- backend/evalu8.c(revision 252)
+++ backend/evalu8.c(working copy)
@@ -1533,10 +1533,22 @@
 }
 else
 {   //printf(signed\n);
+e-EV.Vllong = ((targ_ullong)l1)  i2;
+}
+break;
+
+case OPashr:
+if ((targ_ullong) i2  sizeof(targ_ullong) * 8)
+i2 = sizeof(targ_ullong) * 8;
+if (tyuns(tym))
+{   //printf(unsigned\n);
+e-EV.Vullong = ((targ_ullong) l1)  i2;
+}
+else
+{   //printf(signed\n);
 e-EV.Vllong = l1  i2;
 }
 break;
-
 case OPpair:
 switch (tysize[tym])
 {
Index: e2ir.c
===
--- e2ir.c(revision 252)
+++ e2ir.c(working copy)
@@ -3007,7 +3007,7 @@

 elem *ShrAssignExp::toElem(IRState *irs)
 {
-return toElemBin(irs,OPshrass);
+return toElemBin(irs, tyuns(type-ty) ? OPshrass : OPashrass);
 }


@@ -3117,7 +3117,7 @@

 elem *ShrExp::toElem(IRState *irs)
 {
-return toElemBin(irs,OPshr);
+return toElemBin(irs, tyuns(type-ty) ? OPshr : OPashr);
 }

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