This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c/2623: Wrong code when accessing unsigned short in a structure.
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c/2623: Wrong code when accessing unsigned short in a structure.
- From: niels dot beier at intel dot com
- Date: 24 Apr 2001 10:29:54 -0000
- Reply-To: niels dot beier at intel dot com
>Number: 2623
>Category: c
>Synopsis: Wrong code when accessing unsigned short in a structure.
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Tue Apr 24 03:36:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: Niels Beier
>Release: 2.95.3 (20010315)
>Organization:
>Environment:
host: SunOs 5.6
target: arm-little-elf
Note: We are mixing arm and thumb code and we have therefore
added the thumb-interwork option to the library compilation:
TCFLGS = -fleading-underscore -mthumb-interwork
>Description:
Wrong code is generated when cross compiling the attached code for the arm architecture. An unsigned short (16 bit) in a structure) is accessed as a 32 bit integer.
>How-To-Repeat:
The following piece of C code generates wrong assembler code (accesses a unsigned short as an 32 bit integer).
2/proj/tools/arm/bin/arm-little-elf-gcc -O2 -g -Wall -c /2/proj/appl/router/ppp/45/test.c -o gal/test.o
The following warnings are generated:
line 21: initialization makes pointer from integer without a cast
line 45: initialization makes pointer from integer without a cast
*****file: test.c ***********************************
typedef struct NBnotification_t {
unsigned short code;
unsigned short prio;
unsigned short env;
char *txt;
unsigned long ssp;
unsigned char idlen;
unsigned char *id;
unsigned char trap;
unsigned char varbind_switch;
unsigned long filter;
} NBNOTIFICATION;
static NBNOTIFICATION NBNotifications[] =
{
{ 1, 2, 3,
4, 5,
0, 0, 0, 0,
6},
{ 1,2,3,
4, 0,
12, 0, 13, 0,
14 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
NBNOTIFICATION *nbFindNotif(unsigned short code)
{
NBNOTIFICATION *not = &NBNotifications[0];
while (not->code != (unsigned short)0)
{
if (code == not->code)
return(not);
not++;
}
return(0);
}
*********************************
The resulting disassembled output is listed below:
gal/test.o: file format elf32-littlearm
Disassembly of section .text:
00000000 <nbFindNotif>:
0: e1a0c00d mov r12, sp
4: e92dd800 stmdb sp!, {r11, r12, lr, pc}
8: e24cb004 sub r11, r12, #4 ; 0x4
c: e59f1038 ldr r1, [pc, #38] ; 4c <nbFindNotif+0x4c>
10: e1a00800 mov r0, r0, lsl #16
14: e1d120b0 ldrh r2, [r1]
18: e1a00840 mov r0, r0, asr #16
1c: e3520000 cmp r2, #0 ; 0x0
20: 0a00000f beq 64 <nbFindNotif+0x64>
24: e1a03800 mov r3, r0, lsl #16
28: e1a00823 mov r0, r3, lsr #16
2c: e1500002 cmp r0, r2
30: 01a00001 moveq r0, r1
34: 091ba800 ldmeqdb r11, {r11, sp, pc}
38: e5b12020 ldr r2, [r1, #32]! /* Wrong: should be ldrh */
3c: e3520000 cmp r2, #0 ; 0x0
40: 1a000009 bne 6c <nbFindNotif+0x6c>
44: e3a00000 mov r0, #0 ; 0x0
48: e91ba800 ldmdb r11, {r11, sp, pc}
4c: 00000000 andeq r0, r0, r0
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: