[Bug c/40394] New: Variable values calculated differently depending on storage class

2009-06-10 Thread goran dot steen at enea dot com
/* CODE EXAMPLE ***/ 
#include  
#include  

typedef unsigned int U32; 
typedef unsigned short U16; 
typedef unsigned char U8; 

#ifndef __GNUC__ 
#define __attribute__(a) 
#endif /* __GNUC__ */ 
#define APP6DR_PACK_STRUCT __attribute__((packed)) 

#define APP6DR_INLINE_FUNC(func) \ 
   __inline__ func __attribute__((always_inline)); \ 
   extern __inline__ __attribute__((gnu_inline)) func 

struct app6drIpHdr 
{ 
   unsigned int ip_v :4; 
   unsigned int ip_hl :4; 
   U8 ip_tos; 
   U16 ip_len; 
   U16 ip_id; 
   U16 ip_off; 
   U8 ip_ttl; 
   U8 ip_p; 
   U16 ip_sum; 
   struct 
   { 
  U32 ip_sa; 
  U32 ip_da; 
   } ip_addr_r; 
} APP6DR_PACK_STRUCT; 
typedef struct app6drIpHdr App6drIpHdr; 

#define APP6DR_CALC_CSUM(hdr_p,len,cs) App6dr_calcCs16((const char*)(hdr_p),
(len), &(cs)) 
APP6DR_INLINE_FUNC(void App6dr_calcCs16(const char* hdr_p, 
U32 len, 
volatile U16* cs_p)) 
{ 
   U32 i, sum; 
   for(i=0, sum=0; i<(len)/2; i++) 
   { 
  U32 val = ((U32*)hdr_p)[i]; 
  sum += ((val&0x) + (val>>16)); 
   } 
   if ((len) & 1) sum += ((U16*)hdr_p)[(len)-1]; 
   while(sum>>16) sum = (sum&0x)+(sum>>16); 
   *cs_p = (U16)(~sum); 
} 

#define APP6DR_CALC_IPV4_CSUM(ipv4_p) \ 
   (ipv4_p)->ip_sum = 0x; \ 
   APP6DR_CALC_CSUM((char*)(ipv4_p),sizeof(App6drIpHdr)/2,(ipv4_p)->ip_sum) 


#define DOIT() \ 
  memset((void*)&iph, 0xfe, sizeof(App6drIpHdr)); \ 
  iph.ip_v = 4; \ 
  iph.ip_hl = 5; \ 
  iph.ip_tos = 0; \ 
  iph.ip_len = 0; \ 
  iph.ip_id = 0; \ 
  iph.ip_off = 0; \ 
  iph.ip_ttl = 64; /* XXX */ \ 
  iph.ip_p = 50; /* ESP */ \ 
  iph.ip_addr_r.ip_sa = (U32) sa; \ 
  iph.ip_addr_r.ip_da = (U32) da; \ 
  APP6DR_CALC_IPV4_CSUM(&iph);\ 
  fprintf(stderr, "checksum = 0x%04x\n", iph.ip_sum); 


void testchksum2(U32 sa, U32 da) 
{ 
  static App6drIpHdr iph; 
  DOIT(); 
} 

void testchksum1(U32 sa, U32 da) 
{ 
  App6drIpHdr iph; 
  DOIT(); 
} 

int main() 
{ 
testchksum1(0x0a0a0a14, 0x0a0a0a01); 
testchksum2(0x0a0a0a14, 0x0a0a0a01); 
return 0; 
} 
/ END OF CODE EXAMPLE **/ 


Compiled with 
gcc -Os -Wall -pedantic main.c -o runme

Output:
checksum = 0xa89c
checksum = 0xa542

The only difference between outputs are that the variables made calculations on
have different storage classes, ie automatic and static.


-- 
   Summary: Variable values calculated differently depending on
storage class
   Product: gcc
   Version: 4.2.3
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: goran dot steen at enea dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40394



[Bug c/40395] New: Variable values calculated differently depending on storage class

2009-06-10 Thread goran dot steen at enea dot com
/* CODE EXAMPLE ***/ 
#include  
#include  

typedef unsigned int U32; 
typedef unsigned short U16; 
typedef unsigned char U8; 

#ifndef __GNUC__ 
#define __attribute__(a) 
#endif /* __GNUC__ */ 
#define APP6DR_PACK_STRUCT __attribute__((packed)) 

#define APP6DR_INLINE_FUNC(func) \ 
   __inline__ func __attribute__((always_inline)); \ 
   extern __inline__ __attribute__((gnu_inline)) func 

struct app6drIpHdr 
{ 
   unsigned int ip_v :4; 
   unsigned int ip_hl :4; 
   U8 ip_tos; 
   U16 ip_len; 
   U16 ip_id; 
   U16 ip_off; 
   U8 ip_ttl; 
   U8 ip_p; 
   U16 ip_sum; 
   struct 
   { 
  U32 ip_sa; 
  U32 ip_da; 
   } ip_addr_r; 
} APP6DR_PACK_STRUCT; 
typedef struct app6drIpHdr App6drIpHdr; 

#define APP6DR_CALC_CSUM(hdr_p,len,cs) App6dr_calcCs16((const char*)(hdr_p),
(len), &(cs)) 
APP6DR_INLINE_FUNC(void App6dr_calcCs16(const char* hdr_p, 
U32 len, 
volatile U16* cs_p)) 
{ 
   U32 i, sum; 
   for(i=0, sum=0; i<(len)/2; i++) 
   { 
  U32 val = ((U32*)hdr_p)[i]; 
  sum += ((val&0x) + (val>>16)); 
   } 
   if ((len) & 1) sum += ((U16*)hdr_p)[(len)-1]; 
   while(sum>>16) sum = (sum&0x)+(sum>>16); 
   *cs_p = (U16)(~sum); 
} 

#define APP6DR_CALC_IPV4_CSUM(ipv4_p) \ 
   (ipv4_p)->ip_sum = 0x; \ 
   APP6DR_CALC_CSUM((char*)(ipv4_p),sizeof(App6drIpHdr)/2,(ipv4_p)->ip_sum) 


#define DOIT() \ 
  memset((void*)&iph, 0xfe, sizeof(App6drIpHdr)); \ 
  iph.ip_v = 4; \ 
  iph.ip_hl = 5; \ 
  iph.ip_tos = 0; \ 
  iph.ip_len = 0; \ 
  iph.ip_id = 0; \ 
  iph.ip_off = 0; \ 
  iph.ip_ttl = 64; /* XXX */ \ 
  iph.ip_p = 50; /* ESP */ \ 
  iph.ip_addr_r.ip_sa = (U32) sa; \ 
  iph.ip_addr_r.ip_da = (U32) da; \ 
  APP6DR_CALC_IPV4_CSUM(&iph);\ 
  fprintf(stderr, "checksum = 0x%04x\n", iph.ip_sum); 


void testchksum2(U32 sa, U32 da) 
{ 
  static App6drIpHdr iph; 
  DOIT(); 
} 

void testchksum1(U32 sa, U32 da) 
{ 
  App6drIpHdr iph; 
  DOIT(); 
} 

int main() 
{ 
testchksum1(0x0a0a0a14, 0x0a0a0a01); 
testchksum2(0x0a0a0a14, 0x0a0a0a01); 
return 0; 
} 
/ END OF CODE EXAMPLE **/ 


Compiled with 
gcc -Os -Wall -pedantic main.c -o runme

Output:
checksum = 0xa89c
checksum = 0xa542

The only difference between outputs are that the variables made calculations on
have different storage classes, ie automatic and static.


-- 
   Summary: Variable values calculated differently depending on
storage class
   Product: gcc
   Version: 4.2.3
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: goran dot steen at enea dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40395



[Bug c/40396] New: Variable values calculated differently depending on storage class

2009-06-10 Thread goran dot steen at enea dot com
/* CODE EXAMPLE ***/ 
#include  
#include  

typedef unsigned int U32; 
typedef unsigned short U16; 
typedef unsigned char U8; 

#ifndef __GNUC__ 
#define __attribute__(a) 
#endif /* __GNUC__ */ 
#define APP6DR_PACK_STRUCT __attribute__((packed)) 

#define APP6DR_INLINE_FUNC(func) \ 
   __inline__ func __attribute__((always_inline)); \ 
   extern __inline__ __attribute__((gnu_inline)) func 

struct app6drIpHdr 
{ 
   unsigned int ip_v :4; 
   unsigned int ip_hl :4; 
   U8 ip_tos; 
   U16 ip_len; 
   U16 ip_id; 
   U16 ip_off; 
   U8 ip_ttl; 
   U8 ip_p; 
   U16 ip_sum; 
   struct 
   { 
  U32 ip_sa; 
  U32 ip_da; 
   } ip_addr_r; 
} APP6DR_PACK_STRUCT; 
typedef struct app6drIpHdr App6drIpHdr; 

#define APP6DR_CALC_CSUM(hdr_p,len,cs) App6dr_calcCs16((const char*)(hdr_p),
(len), &(cs)) 
APP6DR_INLINE_FUNC(void App6dr_calcCs16(const char* hdr_p, 
U32 len, 
volatile U16* cs_p)) 
{ 
   U32 i, sum; 
   for(i=0, sum=0; i<(len)/2; i++) 
   { 
  U32 val = ((U32*)hdr_p)[i]; 
  sum += ((val&0x) + (val>>16)); 
   } 
   if ((len) & 1) sum += ((U16*)hdr_p)[(len)-1]; 
   while(sum>>16) sum = (sum&0x)+(sum>>16); 
   *cs_p = (U16)(~sum); 
} 

#define APP6DR_CALC_IPV4_CSUM(ipv4_p) \ 
   (ipv4_p)->ip_sum = 0x; \ 
   APP6DR_CALC_CSUM((char*)(ipv4_p),sizeof(App6drIpHdr)/2,(ipv4_p)->ip_sum) 


#define DOIT() \ 
  memset((void*)&iph, 0xfe, sizeof(App6drIpHdr)); \ 
  iph.ip_v = 4; \ 
  iph.ip_hl = 5; \ 
  iph.ip_tos = 0; \ 
  iph.ip_len = 0; \ 
  iph.ip_id = 0; \ 
  iph.ip_off = 0; \ 
  iph.ip_ttl = 64; /* XXX */ \ 
  iph.ip_p = 50; /* ESP */ \ 
  iph.ip_addr_r.ip_sa = (U32) sa; \ 
  iph.ip_addr_r.ip_da = (U32) da; \ 
  APP6DR_CALC_IPV4_CSUM(&iph);\ 
  fprintf(stderr, "checksum = 0x%04x\n", iph.ip_sum); 


void testchksum2(U32 sa, U32 da) 
{ 
  static App6drIpHdr iph; 
  DOIT(); 
} 

void testchksum1(U32 sa, U32 da) 
{ 
  App6drIpHdr iph; 
  DOIT(); 
} 

int main() 
{ 
testchksum1(0x0a0a0a14, 0x0a0a0a01); 
testchksum2(0x0a0a0a14, 0x0a0a0a01); 
return 0; 
} 
/ END OF CODE EXAMPLE **/ 


Compiled with 
gcc -Os -Wall -pedantic main.c -o runme

Output:
checksum = 0xa89c
checksum = 0xa542

The only difference between outputs are that the variables made calculations on
have different storage classes, ie automatic and static.


-- 
   Summary: Variable values calculated differently depending on
storage class
   Product: gcc
   Version: 4.2.3
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: goran dot steen at enea dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40396



[Bug c/40397] New: Variable values calculated differently depending on storage class

2009-06-10 Thread goran dot steen at enea dot com
/* CODE EXAMPLE ***/ 
#include  
#include  

typedef unsigned int U32; 
typedef unsigned short U16; 
typedef unsigned char U8; 

#ifndef __GNUC__ 
#define __attribute__(a) 
#endif /* __GNUC__ */ 
#define APP6DR_PACK_STRUCT __attribute__((packed)) 

#define APP6DR_INLINE_FUNC(func) \ 
   __inline__ func __attribute__((always_inline)); \ 
   extern __inline__ __attribute__((gnu_inline)) func 

struct app6drIpHdr 
{ 
   unsigned int ip_v :4; 
   unsigned int ip_hl :4; 
   U8 ip_tos; 
   U16 ip_len; 
   U16 ip_id; 
   U16 ip_off; 
   U8 ip_ttl; 
   U8 ip_p; 
   U16 ip_sum; 
   struct 
   { 
  U32 ip_sa; 
  U32 ip_da; 
   } ip_addr_r; 
} APP6DR_PACK_STRUCT; 
typedef struct app6drIpHdr App6drIpHdr; 

#define APP6DR_CALC_CSUM(hdr_p,len,cs) App6dr_calcCs16((const char*)(hdr_p),
(len), &(cs)) 
APP6DR_INLINE_FUNC(void App6dr_calcCs16(const char* hdr_p, 
U32 len, 
volatile U16* cs_p)) 
{ 
   U32 i, sum; 
   for(i=0, sum=0; i<(len)/2; i++) 
   { 
  U32 val = ((U32*)hdr_p)[i]; 
  sum += ((val&0x) + (val>>16)); 
   } 
   if ((len) & 1) sum += ((U16*)hdr_p)[(len)-1]; 
   while(sum>>16) sum = (sum&0x)+(sum>>16); 
   *cs_p = (U16)(~sum); 
} 

#define APP6DR_CALC_IPV4_CSUM(ipv4_p) \ 
   (ipv4_p)->ip_sum = 0x; \ 
   APP6DR_CALC_CSUM((char*)(ipv4_p),sizeof(App6drIpHdr)/2,(ipv4_p)->ip_sum) 


#define DOIT() \ 
  memset((void*)&iph, 0xfe, sizeof(App6drIpHdr)); \ 
  iph.ip_v = 4; \ 
  iph.ip_hl = 5; \ 
  iph.ip_tos = 0; \ 
  iph.ip_len = 0; \ 
  iph.ip_id = 0; \ 
  iph.ip_off = 0; \ 
  iph.ip_ttl = 64; /* XXX */ \ 
  iph.ip_p = 50; /* ESP */ \ 
  iph.ip_addr_r.ip_sa = (U32) sa; \ 
  iph.ip_addr_r.ip_da = (U32) da; \ 
  APP6DR_CALC_IPV4_CSUM(&iph);\ 
  fprintf(stderr, "checksum = 0x%04x\n", iph.ip_sum); 


void testchksum2(U32 sa, U32 da) 
{ 
  static App6drIpHdr iph; 
  DOIT(); 
} 

void testchksum1(U32 sa, U32 da) 
{ 
  App6drIpHdr iph; 
  DOIT(); 
} 

int main() 
{ 
testchksum1(0x0a0a0a14, 0x0a0a0a01); 
testchksum2(0x0a0a0a14, 0x0a0a0a01); 
return 0; 
} 
/ END OF CODE EXAMPLE **/ 


Compiled with 
gcc -Os -Wall -pedantic main.c -o runme

Output:
checksum = 0xa89c
checksum = 0xa542

The only difference between outputs are that the variables made calculations on
have different storage classes, ie automatic and static.


-- 
   Summary: Variable values calculated differently depending on
storage class
   Product: gcc
   Version: 4.2.3
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: goran dot steen at enea dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40397



[Bug c/40398] New: Variable values calculated differently depending on storage class

2009-06-10 Thread goran dot steen at enea dot com
/* CODE EXAMPLE ***/ 
#include  
#include  

typedef unsigned int U32; 
typedef unsigned short U16; 
typedef unsigned char U8; 

#ifndef __GNUC__ 
#define __attribute__(a) 
#endif /* __GNUC__ */ 
#define APP6DR_PACK_STRUCT __attribute__((packed)) 

#define APP6DR_INLINE_FUNC(func) \ 
   __inline__ func __attribute__((always_inline)); \ 
   extern __inline__ __attribute__((gnu_inline)) func 

struct app6drIpHdr 
{ 
   unsigned int ip_v :4; 
   unsigned int ip_hl :4; 
   U8 ip_tos; 
   U16 ip_len; 
   U16 ip_id; 
   U16 ip_off; 
   U8 ip_ttl; 
   U8 ip_p; 
   U16 ip_sum; 
   struct 
   { 
  U32 ip_sa; 
  U32 ip_da; 
   } ip_addr_r; 
} APP6DR_PACK_STRUCT; 
typedef struct app6drIpHdr App6drIpHdr; 

#define APP6DR_CALC_CSUM(hdr_p,len,cs) App6dr_calcCs16((const char*)(hdr_p),
(len), &(cs)) 
APP6DR_INLINE_FUNC(void App6dr_calcCs16(const char* hdr_p, 
U32 len, 
volatile U16* cs_p)) 
{ 
   U32 i, sum; 
   for(i=0, sum=0; i<(len)/2; i++) 
   { 
  U32 val = ((U32*)hdr_p)[i]; 
  sum += ((val&0x) + (val>>16)); 
   } 
   if ((len) & 1) sum += ((U16*)hdr_p)[(len)-1]; 
   while(sum>>16) sum = (sum&0x)+(sum>>16); 
   *cs_p = (U16)(~sum); 
} 

#define APP6DR_CALC_IPV4_CSUM(ipv4_p) \ 
   (ipv4_p)->ip_sum = 0x; \ 
   APP6DR_CALC_CSUM((char*)(ipv4_p),sizeof(App6drIpHdr)/2,(ipv4_p)->ip_sum) 


#define DOIT() \ 
  memset((void*)&iph, 0xfe, sizeof(App6drIpHdr)); \ 
  iph.ip_v = 4; \ 
  iph.ip_hl = 5; \ 
  iph.ip_tos = 0; \ 
  iph.ip_len = 0; \ 
  iph.ip_id = 0; \ 
  iph.ip_off = 0; \ 
  iph.ip_ttl = 64; /* XXX */ \ 
  iph.ip_p = 50; /* ESP */ \ 
  iph.ip_addr_r.ip_sa = (U32) sa; \ 
  iph.ip_addr_r.ip_da = (U32) da; \ 
  APP6DR_CALC_IPV4_CSUM(&iph);\ 
  fprintf(stderr, "checksum = 0x%04x\n", iph.ip_sum); 


void testchksum2(U32 sa, U32 da) 
{ 
  static App6drIpHdr iph; 
  DOIT(); 
} 

void testchksum1(U32 sa, U32 da) 
{ 
  App6drIpHdr iph; 
  DOIT(); 
} 

int main() 
{ 
testchksum1(0x0a0a0a14, 0x0a0a0a01); 
testchksum2(0x0a0a0a14, 0x0a0a0a01); 
return 0; 
} 
/ END OF CODE EXAMPLE **/ 


Compiled with 
gcc -Os -Wall -pedantic main.c -o runme

Output:
checksum = 0xa89c
checksum = 0xa542

The only difference between outputs are that the variables made calculations on
have different storage classes, ie automatic and static.


-- 
   Summary: Variable values calculated differently depending on
storage class
   Product: gcc
   Version: 4.2.3
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: goran dot steen at enea dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40398



[Bug c/40399] New: Variable values calculated differently depending on storage class

2009-06-10 Thread goran dot steen at enea dot com
/* CODE EXAMPLE ***/ 
#include  
#include  

typedef unsigned int U32; 
typedef unsigned short U16; 
typedef unsigned char U8; 

#ifndef __GNUC__ 
#define __attribute__(a) 
#endif /* __GNUC__ */ 
#define APP6DR_PACK_STRUCT __attribute__((packed)) 

#define APP6DR_INLINE_FUNC(func) \ 
   __inline__ func __attribute__((always_inline)); \ 
   extern __inline__ __attribute__((gnu_inline)) func 

struct app6drIpHdr 
{ 
   unsigned int ip_v :4; 
   unsigned int ip_hl :4; 
   U8 ip_tos; 
   U16 ip_len; 
   U16 ip_id; 
   U16 ip_off; 
   U8 ip_ttl; 
   U8 ip_p; 
   U16 ip_sum; 
   struct 
   { 
  U32 ip_sa; 
  U32 ip_da; 
   } ip_addr_r; 
} APP6DR_PACK_STRUCT; 
typedef struct app6drIpHdr App6drIpHdr; 

#define APP6DR_CALC_CSUM(hdr_p,len,cs) App6dr_calcCs16((const char*)(hdr_p),
(len), &(cs)) 
APP6DR_INLINE_FUNC(void App6dr_calcCs16(const char* hdr_p, 
U32 len, 
volatile U16* cs_p)) 
{ 
   U32 i, sum; 
   for(i=0, sum=0; i<(len)/2; i++) 
   { 
  U32 val = ((U32*)hdr_p)[i]; 
  sum += ((val&0x) + (val>>16)); 
   } 
   if ((len) & 1) sum += ((U16*)hdr_p)[(len)-1]; 
   while(sum>>16) sum = (sum&0x)+(sum>>16); 
   *cs_p = (U16)(~sum); 
} 

#define APP6DR_CALC_IPV4_CSUM(ipv4_p) \ 
   (ipv4_p)->ip_sum = 0x; \ 
   APP6DR_CALC_CSUM((char*)(ipv4_p),sizeof(App6drIpHdr)/2,(ipv4_p)->ip_sum) 


#define DOIT() \ 
  memset((void*)&iph, 0xfe, sizeof(App6drIpHdr)); \ 
  iph.ip_v = 4; \ 
  iph.ip_hl = 5; \ 
  iph.ip_tos = 0; \ 
  iph.ip_len = 0; \ 
  iph.ip_id = 0; \ 
  iph.ip_off = 0; \ 
  iph.ip_ttl = 64; /* XXX */ \ 
  iph.ip_p = 50; /* ESP */ \ 
  iph.ip_addr_r.ip_sa = (U32) sa; \ 
  iph.ip_addr_r.ip_da = (U32) da; \ 
  APP6DR_CALC_IPV4_CSUM(&iph);\ 
  fprintf(stderr, "checksum = 0x%04x\n", iph.ip_sum); 


void testchksum2(U32 sa, U32 da) 
{ 
  static App6drIpHdr iph; 
  DOIT(); 
} 

void testchksum1(U32 sa, U32 da) 
{ 
  App6drIpHdr iph; 
  DOIT(); 
} 

int main() 
{ 
testchksum1(0x0a0a0a14, 0x0a0a0a01); 
testchksum2(0x0a0a0a14, 0x0a0a0a01); 
return 0; 
} 
/ END OF CODE EXAMPLE **/ 


Compiled with 
gcc -Os -Wall -pedantic main.c -o runme

Output:
checksum = 0xa89c
checksum = 0xa542

The only difference between outputs are that the variables made calculations on
have different storage classes, ie automatic and static.


-- 
   Summary: Variable values calculated differently depending on
storage class
   Product: gcc
   Version: 4.2.3
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: goran dot steen at enea dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40399



[Bug c/40400] New: Variable values calculated differently depending on storage class

2009-06-10 Thread goran dot steen at enea dot com
/* CODE EXAMPLE ***/ 
#include  
#include  

typedef unsigned int U32; 
typedef unsigned short U16; 
typedef unsigned char U8; 

#ifndef __GNUC__ 
#define __attribute__(a) 
#endif /* __GNUC__ */ 
#define APP6DR_PACK_STRUCT __attribute__((packed)) 

#define APP6DR_INLINE_FUNC(func) \ 
   __inline__ func __attribute__((always_inline)); \ 
   extern __inline__ __attribute__((gnu_inline)) func 

struct app6drIpHdr 
{ 
   unsigned int ip_v :4; 
   unsigned int ip_hl :4; 
   U8 ip_tos; 
   U16 ip_len; 
   U16 ip_id; 
   U16 ip_off; 
   U8 ip_ttl; 
   U8 ip_p; 
   U16 ip_sum; 
   struct 
   { 
  U32 ip_sa; 
  U32 ip_da; 
   } ip_addr_r; 
} APP6DR_PACK_STRUCT; 
typedef struct app6drIpHdr App6drIpHdr; 

#define APP6DR_CALC_CSUM(hdr_p,len,cs) App6dr_calcCs16((const char*)(hdr_p),
(len), &(cs)) 
APP6DR_INLINE_FUNC(void App6dr_calcCs16(const char* hdr_p, 
U32 len, 
volatile U16* cs_p)) 
{ 
   U32 i, sum; 
   for(i=0, sum=0; i<(len)/2; i++) 
   { 
  U32 val = ((U32*)hdr_p)[i]; 
  sum += ((val&0x) + (val>>16)); 
   } 
   if ((len) & 1) sum += ((U16*)hdr_p)[(len)-1]; 
   while(sum>>16) sum = (sum&0x)+(sum>>16); 
   *cs_p = (U16)(~sum); 
} 

#define APP6DR_CALC_IPV4_CSUM(ipv4_p) \ 
   (ipv4_p)->ip_sum = 0x; \ 
   APP6DR_CALC_CSUM((char*)(ipv4_p),sizeof(App6drIpHdr)/2,(ipv4_p)->ip_sum) 


#define DOIT() \ 
  memset((void*)&iph, 0xfe, sizeof(App6drIpHdr)); \ 
  iph.ip_v = 4; \ 
  iph.ip_hl = 5; \ 
  iph.ip_tos = 0; \ 
  iph.ip_len = 0; \ 
  iph.ip_id = 0; \ 
  iph.ip_off = 0; \ 
  iph.ip_ttl = 64; /* XXX */ \ 
  iph.ip_p = 50; /* ESP */ \ 
  iph.ip_addr_r.ip_sa = (U32) sa; \ 
  iph.ip_addr_r.ip_da = (U32) da; \ 
  APP6DR_CALC_IPV4_CSUM(&iph);\ 
  fprintf(stderr, "checksum = 0x%04x\n", iph.ip_sum); 


void testchksum2(U32 sa, U32 da) 
{ 
  static App6drIpHdr iph; 
  DOIT(); 
} 

void testchksum1(U32 sa, U32 da) 
{ 
  App6drIpHdr iph; 
  DOIT(); 
} 

int main() 
{ 
testchksum1(0x0a0a0a14, 0x0a0a0a01); 
testchksum2(0x0a0a0a14, 0x0a0a0a01); 
return 0; 
} 
/ END OF CODE EXAMPLE **/ 


Compiled with 
gcc -Os -Wall -pedantic main.c -o runme

Output:
checksum = 0xa89c
checksum = 0xa542

The only difference between outputs are that the variables made calculations on
have different storage classes, ie automatic and static.


-- 
   Summary: Variable values calculated differently depending on
storage class
   Product: gcc
   Version: 4.2.3
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: goran dot steen at enea dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40400



[Bug c/40395] Variable values calculated differently depending on storage class

2009-06-10 Thread goran dot steen at enea dot com


--- Comment #1 from goran dot steen at enea dot com  2009-06-10 12:42 
---


*** This bug has been marked as a duplicate of 40394 ***


-- 

goran dot steen at enea dot com changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40395



[Bug c/40394] Variable values calculated differently depending on storage class

2009-06-10 Thread goran dot steen at enea dot com


--- Comment #1 from goran dot steen at enea dot com  2009-06-10 12:42 
---
*** Bug 40395 has been marked as a duplicate of this bug. ***


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40394



[Bug c/40396] Variable values calculated differently depending on storage class

2009-06-10 Thread goran dot steen at enea dot com


--- Comment #1 from goran dot steen at enea dot com  2009-06-10 12:42 
---


*** This bug has been marked as a duplicate of 40394 ***


-- 

goran dot steen at enea dot com changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40396



[Bug c/40394] Variable values calculated differently depending on storage class

2009-06-10 Thread goran dot steen at enea dot com


--- Comment #2 from goran dot steen at enea dot com  2009-06-10 12:42 
---
*** Bug 40396 has been marked as a duplicate of this bug. ***


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40394



[Bug c/40394] Variable values calculated differently depending on storage class

2009-06-10 Thread goran dot steen at enea dot com


--- Comment #3 from goran dot steen at enea dot com  2009-06-10 12:42 
---
*** Bug 40397 has been marked as a duplicate of this bug. ***


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40394



[Bug c/40397] Variable values calculated differently depending on storage class

2009-06-10 Thread goran dot steen at enea dot com


--- Comment #1 from goran dot steen at enea dot com  2009-06-10 12:42 
---


*** This bug has been marked as a duplicate of 40394 ***


-- 

goran dot steen at enea dot com changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40397



[Bug c/40394] Variable values calculated differently depending on storage class

2009-06-10 Thread goran dot steen at enea dot com


--- Comment #4 from goran dot steen at enea dot com  2009-06-10 12:43 
---
*** Bug 40398 has been marked as a duplicate of this bug. ***


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40394



[Bug c/40398] Variable values calculated differently depending on storage class

2009-06-10 Thread goran dot steen at enea dot com


--- Comment #1 from goran dot steen at enea dot com  2009-06-10 12:43 
---


*** This bug has been marked as a duplicate of 40394 ***


-- 

goran dot steen at enea dot com changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40398



[Bug c/40394] Variable values calculated differently depending on storage class

2009-06-10 Thread goran dot steen at enea dot com


--- Comment #5 from goran dot steen at enea dot com  2009-06-10 12:43 
---
*** Bug 40399 has been marked as a duplicate of this bug. ***


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40394



[Bug c/40399] Variable values calculated differently depending on storage class

2009-06-10 Thread goran dot steen at enea dot com


--- Comment #1 from goran dot steen at enea dot com  2009-06-10 12:43 
---


*** This bug has been marked as a duplicate of 40394 ***


-- 

goran dot steen at enea dot com changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40399



[Bug c/40400] Variable values calculated differently depending on storage class

2009-06-10 Thread goran dot steen at enea dot com


--- Comment #1 from goran dot steen at enea dot com  2009-06-10 12:43 
---


*** This bug has been marked as a duplicate of 40394 ***


-- 

goran dot steen at enea dot com changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||DUPLICATE


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40400



[Bug c/40394] Variable values calculated differently depending on storage class

2009-06-10 Thread goran dot steen at enea dot com


--- Comment #6 from goran dot steen at enea dot com  2009-06-10 12:43 
---
*** Bug 40400 has been marked as a duplicate of this bug. ***


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40394



[Bug c/40394] Variable values calculated differently depending on storage class

2009-06-11 Thread goran dot steen at enea dot com


--- Comment #8 from goran dot steen at enea dot com  2009-06-12 06:20 
---
Since -pedantic was given as compiler option, gcc should have warned about
violating C aliasing rules.


-- 

goran dot steen at enea dot com changed:

   What|Removed |Added

 CC||goran dot steen at enea dot
   ||com
 Status|RESOLVED|UNCONFIRMED
 Resolution|INVALID |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40394