public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: niels.beier@intel.com To: gcc-gnats@gcc.gnu.org Subject: c/2623: Wrong code when accessing unsigned short in a structure. Date: Tue, 24 Apr 2001 03:36:00 -0000 [thread overview] Message-ID: <20010424102954.6004.qmail@sourceware.cygnus.com> (raw) >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:
reply other threads:[~2001-04-24 3:36 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20010424102954.6004.qmail@sourceware.cygnus.com \ --to=niels.beier@intel.com \ --cc=gcc-gnats@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).