#1632 cast to (void *) loses address addition

closed-rejected
None
5
2013-05-25
2010-04-05
No

#include <string.h>
#define UIP_LLADDR_LEN 8

struct uip_802154_longaddr {
unsigned char addr[8];
};
typedef struct uip_802154_longaddr uip_lladdr_t;

struct uip_nd6_opt_llao {
unsigned char type;
unsigned char len;
uip_lladdr_t addr;
};

static struct uip_nd6_opt_llao *nd6_opt_llao;

void main (void)
{
unsigned char buf[300];
nd6_opt_llao = (struct uip_nd6_opt_llao *)buf;
//generated code for this is correct
memset((unsigned char *)(&nd6_opt_llao->addr) + UIP_LLADDR_LEN, 0, 6);
//generated code for this is WRONG
memset((void *)(&nd6_opt_llao->addr) + UIP_LLADDR_LEN, 0, 6);

}

void * code is missing:

< 0014 74 08 148 mov a,#0x08
< 0016 2A 149 add a,r2
< 0017 FA 150 mov r2,a
< 0018 E4 151 clr a

user@instant-contiki:~/sdcc_bug$ sdcc -v
SDCC : mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08 2.7.0 #4818 (Jan 18 2008) (UNIX)

as well as more recent release supporting huge memory model

Discussion

  • Maarten Brock

    Maarten Brock - 2010-04-06
    • milestone: --> non_bugs
    • assigned_to: nobody --> maartenbrock
    • status: open --> closed-rejected
     
  • Maarten Brock

    Maarten Brock - 2010-04-06

    This is no bug. The cast preceeds the addition and the size of void is zero.

     
  • Anthony Asterisk

    This differs from GCC and makes SDCC incompatible with code written for GCC. Does it really serve any useful purpose.

    Could a warning be added when arithmetic with a void * is attempted?

    This wasted a significant amount of my time and will burn many other developers who attempt to use SDCC to compile tools designed with GCC.

    BTW...here is the description of the GCC behavior from their user manual:

    4.17 Arithmetic on void- and Function-Pointers

    In GNU C, addition and subtraction operations are supported on pointers to void and on pointers to functions. This is done by treating the size of a void or of a function as 1.

    A consequence of this is that sizeof is also allowed on void and on function types, and returns 1.

    The option `-Wpointer-arith' requests a warning if these extensions are used.

     

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