#1334 INT plus CHAR makes wrong assembly codes

closed-fixed
nobody
5
2013-05-25
2007-05-21
No

/*** simple.c for testing ***/
#include <sdcc-lib.h>

#include <pic16f84a.h>

static signed int x=0;
static unsigned char y=1;

void main() {
x += y;
x += y;
while (1) {}
}
/*** source end ***/

SDCC 2.7.0 #4802 (May 21 2007) (UNIX)

Two lines of (x += y) makes different assembly codes.
It seems the first line turns wrong.

Initially, x=0x0000.
The first line of (x += y) makes x from 0x0000 to 0x0101 (shoud be 0x0001).
Next line makes x from 0x0101 to 0x0102 (correct).

'x += (singed int)y;' makes the same result as above 'x += y'.

Next sorce gets correct result (x: 0x0000 --> 0x0001 --> 0x0002).

/*** seems correct result ***/
#include <sdcc-lib.h>

#include <pic16f84a.h>

static signed int x=0, w;
static unsigned char y=1;

void main() {
w = y;
x += w;
x += w;
while (1) {}
}
/*** source end ***/

Discussion

  • Raphael Neider

    Raphael Neider - 2007-05-21
    • milestone: --> 100454
    • assigned_to: nobody --> tecodev
     
  • Raphael Neider

    Raphael Neider - 2007-05-21

    Logged In: YES
    user_id=1115835
    Originator: NO

    This bug is caused by the slightly buggy pcode optimization (the contents of WREG is used, but not correctly set up by the `optimized' code). Please compile your code with
    --no-pcode-opt
    to disable the optimisation and prevent the bug from surfacing.
    Of course, this comes at the cost of increased code size...

    Regards,
    Raphael

    I leave this open until I get to fix the optimisation...

     
  • Raphael Neider

    Raphael Neider - 2007-05-21

    Logged In: YES
    user_id=1115835
    Originator: NO

    OK, here is a patch to fix the pCode optimization, along with a regression test and improvements for the pic testsuite (src/regression).
    Patch is against SDCC r4806.

    File Added: pcodeopt.patch

     
  • Raphael Neider

    Raphael Neider - 2007-05-21

    Fix for the buggy PIC14 pCode optimization

     
    Attachments
  • Raphael Neider

    Raphael Neider - 2007-05-21
    • milestone: 100454 --> fixed
    • assigned_to: tecodev --> nobody
    • status: open --> closed-fixed
     
  • Raphael Neider

    Raphael Neider - 2007-05-21

    Logged In: YES
    user_id=1115835
    Originator: NO

    Fix is committed in r4807 and---thanks to Borut---will make it into the 2.7.0 release.

    Regards,
    Raphael

     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks