Jump to content
Sign in to follow this  
BrownFrog

Boostc Incorrect Code Generation

Recommended Posts

OK, here is my third bug report on BoostC related to nested structures found in Microchip's TCP/IP code. The following code generates incorrect accesses to elements within the 'packet' object.

 

#include <system.h>

typedef unsigned char BYTE;
typedef unsigned long DWORD;

typedef union _IP_ADDR
{
   BYTE        v[4];
   DWORD       Val;
} IP_ADDR;

typedef struct _MAC_ADDR
{
   BYTE v[6];
} MAC_ADDR;

typedef struct _NODE_INFO
{
   MAC_ADDR    MACAddr;
   IP_ADDR     IPAddr;
} NODE_INFO;



typedef struct _ARP_PACKET
{
   MAC_ADDR    TargetMACAddr;
   IP_ADDR     TargetIPAddr;
   MAC_ADDR    SenderMACAddr;
   IP_ADDR     SenderIPAddr;
} ARP_PACKET;

void main(void) {
ARP_PACKET packet;

NODE_INFO *remote;

/* This member copy ... */
remote->IPAddr      = packet.SenderIPAddr;
/* should do the same as the following but it 
   uses the wrong offsets in packet. */
   remote->IPAddr.v[0] = packet.SenderIPAddr.v[0];
   remote->IPAddr.v[1] = packet.SenderIPAddr.v[1];
   remote->IPAddr.v[2] = packet.SenderIPAddr.v[2];
   remote->IPAddr.v[3] = packet.SenderIPAddr.v[3];
}

 

The code the compiler produces as shown in the Code view window:

 

	/* This member copy ... */
remote->IPAddr      = packet.SenderIPAddr;
0003  1383 	 BCF STATUS,IRP
0004  1283 	 BCF STATUS, RP0
0005  1303 	 BCF STATUS, RP1
0006  1835 	 BTFSC main_1_remote+D'1',0
0007  1783 	 BSF STATUS,IRP
0008  0834 	 MOVF main_1_remote, W
0009  0084 	 MOVWF FSR
000A  3006 	 MOVLW 0x06
000B  0784 	 ADDWF FSR, F
000C  0820 	 MOVF main_1_packet, W
000D  0080 	 MOVWF INDF
000E  0A84 	 INCF FSR, F
000F  0821 	 MOVF main_1_packet+D'1', W
0010  0080 	 MOVWF INDF
0011  0A84 	 INCF FSR, F
0012  0822 	 MOVF main_1_packet+D'2', W
0013  0080 	 MOVWF INDF
0014  0A84 	 INCF FSR, F
0015  0823 	 MOVF main_1_packet+D'3', W
0016  0080 	 MOVWF INDF

/* should do the same as the following but it 
   uses the wrong offsets in packet. */
   remote->IPAddr.v[0] = packet.SenderIPAddr.v[0];
0017  1383 	 BCF STATUS,IRP
0018  1835 	 BTFSC main_1_remote+D'1',0
0019  1783 	 BSF STATUS,IRP
001A  0834 	 MOVF main_1_remote, W
001B  0084 	 MOVWF FSR
001C  3006 	 MOVLW 0x06
001D  0784 	 ADDWF FSR, F
001E  0830 	 MOVF main_1_packet+D'16', W
001F  0080 	 MOVWF INDF

   remote->IPAddr.v[1] = packet.SenderIPAddr.v[1];
0020  1383 	 BCF STATUS,IRP
0021  1835 	 BTFSC main_1_remote+D'1',0
0022  1783 	 BSF STATUS,IRP
0023  0834 	 MOVF main_1_remote, W
0024  0084 	 MOVWF FSR
0025  3006 	 MOVLW 0x06
0026  0784 	 ADDWF FSR, F
0027  0A84 	 INCF FSR, F
0028  0831 	 MOVF main_1_packet+D'17', W
0029  0080 	 MOVWF INDF

   remote->IPAddr.v[2] = packet.SenderIPAddr.v[2];
002A  1383 	 BCF STATUS,IRP
002B  1835 	 BTFSC main_1_remote+D'1',0
002C  1783 	 BSF STATUS,IRP
002D  0834 	 MOVF main_1_remote, W
002E  0084 	 MOVWF FSR
002F  3006 	 MOVLW 0x06
0030  0784 	 ADDWF FSR, F
0031  3002 	 MOVLW 0x02
0032  0784 	 ADDWF FSR, F
0033  0832 	 MOVF main_1_packet+D'18', W
0034  0080 	 MOVWF INDF

   remote->IPAddr.v[3] = packet.SenderIPAddr.v[3];
0035  1383 	 BCF STATUS,IRP
0036  1835 	 BTFSC main_1_remote+D'1',0
0037  1783 	 BSF STATUS,IRP
0038  0834 	 MOVF main_1_remote, W
0039  0084 	 MOVWF FSR
003A  3006 	 MOVLW 0x06
003B  0784 	 ADDWF FSR, F
003C  3003 	 MOVLW 0x03
003D  0784 	 ADDWF FSR, F
003E  0833 	 MOVF main_1_packet+D'19', W
003F  0080 	 MOVWF INDF

 

Note that the code copying the 32 bit value as a single item accesses addresses 0 through 3 in the packet structure, while the explicit copying code accesses addresses 16 through 19 (the correct addresses). A pity really, because the 32 bit copy produces much better assembler!

 

 

IDE version: 6.70

Compiler: BoostC

Compiler version: 6.70

Target device: PIC18F25J10

OS: WinXP SP2

 

All the best

 

John

Share this post


Link to post
Share on other sites

Are you sure it is incorrect? That code has multiple defines and permutations

of MANY of its structures and common functions.

 

It may be simply linking in the wrong ones, i know ones involving the MAC stuff

are redefined 3 times in different locations. Talk about a UDP strip project from

the abyss.

Share this post


Link to post
Share on other sites
OK, here is my third bug report on BoostC related to nested structures found in Microchip's TCP/IP code. The following code generates incorrect accesses to elements within the 'packet' object.

 

.....

.....

 

IDE version:          6.70

Compiler:              BoostC

Compiler version:  6.70

Target device:        PIC18F25J10

OS:                      WinXP SP2

Yes this is a problem. Its been added to our bug list.

 

Regards

Dave

Share this post


Link to post
Share on other sites

Problem found and fixed. Fix will be available in the next release. Thanks for reporting.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...