#1733 PIC16: ptr dereference silently dropped, bad code generated

open
nobody
PIC16
5
2013-07-16
2010-12-29
No

Compiling the attached source file with the following command:

$ sdcc -mpic16 -p18f65j50 --use-non-free -c xbee_txpacket.c

silently generates bad code. Specifically, the following snippet appears in the assembly output:

; .line 14; xbee_txpacket.c if (!ready_queue.head->field) {
MOVFF _ready_queue, r0x00
MOVF r0x00, W
BNZ _00106_DS_
; .line 15; xbee_txpacket.c LATBbits.LATB0 = 1;

It's quite obvious that the three listed assembly instructions do not do what the source line above them says. The source line should go to the (known-at-compile-time) address of the "head" field of the "ready_queue" structure, *dereference the pointer found there*, and then check whether the byte in "field" at the thus-found structure is zero or not. The assembly instructions, on the other hand, merely check whether the first byte of the "head" pointer itself is zero!

$ sdcc --version
SDCC : pic16/pic14 3.0.0 #6037 (Nov 8 2010) (Linux)

Discussion

  • Christopher Head

    The source file

     
  • Christopher Head

    Interestingly, further investigation suggests this only affects the *FIRST* element of the pointed-to structure; accesses to subsequent elements work fine.

     
  • Maarten Brock

    Maarten Brock - 2011-09-15
    • summary: pointer dereference silently dropped, bad code generated --> PIC16: ptr dereference silently dropped, bad code generated
     
  • Philipp Klaus Krause

    • Category: --> PIC16
     

Log in to post a comment.

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

Sign up for the SourceForge newsletter:





No, thanks