#943 Array and temporary bugs


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

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



  • Raphael Neider

    Raphael Neider - 2005-07-01

    Logged In: YES

    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.

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

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks