#1668 PIC14: struct char interpreted as 4byte value?

closed-fixed
5
2013-05-25
2010-08-02
strobla
No

PIC14 / compiler bug: struct set unsigned char =0 zeroes out 4 bytes instead of 1 byte:

Dear Raphael, dear SDCC developers,

attached you can find a minimal project to reproduce the bug.

If struct value ".d1" is set to zero
and afterwards ".d0" is set to zero
".d0" will be interpreted as long instead as unsigned char?

Tested with r5530 and r5896 - same problem.

Regards, Strobl Anton

main.c:

typedef union {
struct {
unsigned char d0;
unsigned char d1;
unsigned char d2;
unsigned char d3;
unsigned char d4;
unsigned char d5;
unsigned char d6;
unsigned char d7;
};
struct {
unsigned char bytes[8];
};
} MYSTATE;

MYSTATE test1;
MYSTATE test2;

volatile MYSTATE test3;
volatile MYSTATE test4;

void main(void)
{
test1.d1=0; // ok
test1.d0=0; /* generated assembler code false clears
also test1.d1, test1.d2 and test1.d3 */

test2.d0=0; // ok
test2.d1=0; // ok

// test with volatile declared vars
test3.d1=0; // if defined as volatile - ok
test3.d0=0; // ok

test4.d0=0; // ok
test4.d1=0; // ok
}

main.asm (partially)

_main ;Function start
; 2 exit points
;gen.c:5941: size=0/1, offset=0, AOP_TYPE(res)=8
; .line 25; "main.c" test1.d1=0; // ok
BANKSEL _test1
CLRF (_test1 + 1)
;gen.c:5941: size=3/8, offset=0, AOP_TYPE(res)=8
; .line 26; "main.c" test1.d0=0; // generated assembler code false
clears also test1.d1, test1.d2 and test1.d3
CLRF (_test1 + 0)
;gen.c:5941: size=2/8, offset=1, AOP_TYPE(res)=8
CLRF (_test1 + 1)
;gen.c:5941: size=1/8, offset=2, AOP_TYPE(res)=8
CLRF (_test1 + 2)
;gen.c:5941: size=0/8, offset=3, AOP_TYPE(res)=8
CLRF (_test1 + 3)
;gen.c:5941: size=0/1, offset=0, AOP_TYPE(res)=8
; .line 28; "main.c" test2.d0=0; // ok
BANKSEL _test2
CLRF (_test2 + 0)
;gen.c:5941: size=0/1, offset=0, AOP_TYPE(res)=8
; .line 29; "main.c" test2.d1=0; // ok
CLRF (_test2 + 1)
;gen.c:5941: size=0/1, offset=0, AOP_TYPE(res)=8
; .line 32; "main.c" test3.d1=0; // if defined as volatile - ok
BANKSEL _test3
CLRF (_test3 + 1)
;gen.c:5941: size=0/1, offset=0, AOP_TYPE(res)=8
; .line 33; "main.c" test3.d0=0; // ok
CLRF (_test3 + 0)
;gen.c:5941: size=0/1, offset=0, AOP_TYPE(res)=8
; .line 35; "main.c" test4.d0=0; // ok
BANKSEL _test4
CLRF (_test4 + 0)
;gen.c:5941: size=0/1, offset=0, AOP_TYPE(res)=8
; .line 36; "main.c" test4.d1=0; // ok
CLRF (_test4 + 1)
RETURN
; exit point of _main

Discussion

  • Raphael Neider
    Raphael Neider
    2010-08-02

    Fixed in r5906.

     
  • Raphael Neider
    Raphael Neider
    2010-08-02

    • milestone: --> fixed
    • status: open --> closed-fixed
     
  • Raphael Neider
    Raphael Neider
    2012-02-12

    • assigned_to: nobody --> tecodev