Menu

#943 Array and temporary bugs

closed-fixed
5
2013-05-25
2005-06-28
No

Here's a small snippet of code that reproduces two
simple bugs. Sorry if this has already been reported, I
couldn't find the information elsewhere though.

#define __16f627
#include <pic/pic16f627.h>

unsigned char buffer[16];

int main()
{
if (buffer[0] == 0) {
PORTA = buffer[1];
}

if (buffer[0] == 1) {
PORTA = buffer[2];
}

return 0;
}

The first bug is caused by having two if statements (or
a switch statement). It causes a temporary to be
allocated but nothing is ever assigned to the temporary
variable. Having only one if statement doesn't
allocate a temporary and then it works.

The second bug is PORTA not being assigned. If
assigning a constant, it works fine, but assigning from
the array results in no code.

The resulting assembly is below (slightly edited for
brevity):

;entry:
_main ;Function start
;2 compiler
assigned registers:
; r0x21
; s0x7F
_main
;Function start
; if
(buffer[0] == 0) {
000005 1283 bcf 0x3, 0x5 BANKSEL
r0x21
000006 1703 bsf 0x3, 0x6
000007 0830 movf 0x30, w MOVF
r0x21,W
000008 1d03 btfss 0x3, 0x2 BTFSS
STATUS,2
000009 280a goto 0xa GOTO
_00106_DS_
_00106_DS_
; if
(buffer[0] == 1) {
00000a 0b30 decfsz 0x30, w
DECFSZ r0x21,W
00000b 280c goto 0xc GOTO
_00108_DS_
_00108_DS_
; return 0;
00000c 3000 movlw 0 MOVLW
0x00
00000d 00ff movwf 0x7f MOVWF
s0x7F
00000e 3000 movlw 0 MOVLW
0x00
00000f 0008 return RETURN

At address 7, the temporary is being used, but hasn't
yet been assigned to from buffer[0]

And also, as you can see, there is no mention of
assigning to PORTA (there would be if it was a constant
assignment). Perhaps it's being optimised away?

In any case, I hope these are useful. Please drop me
an email at S.McAuliffe@dtsp.co.nz if I can provide any
furtherr information or if I can be of any assistance
in debugging the compiler.

Thanks.

Discussion

  • Raphael Neider

    Raphael Neider - 2005-07-01

    Logged In: YES
    user_id=1115835

    Both bugs have been fixed in SDCC 2.5.1 #1053.

     
  • Raphael Neider

    Raphael Neider - 2005-07-01
    • milestone: --> fixed
    • assigned_to: nobody --> tecodev
    • status: open --> closed-fixed
     

Log in to post a comment.