This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/16691] New: arm-elf-gcc generates wrong-code
- From: "gcc-bugzilla at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 23 Jul 2004 15:01:16 -0000
- Subject: [Bug target/16691] New: arm-elf-gcc generates wrong-code
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
arm-elf-gcc generates wrong-code.
Why it use two 'strb', not one 'strh'?
And why it do 'ldrb'?
Because the 'glob_ptr' is the pointer to external device (16bit only,
volatile), both code could be a problem.
If I removed '__attribute__((__packed__))', gcc generates the code
what I expected.
The gcc (3.4.1, host compiler) and m6811-elf-gcc (3.4.1) generates
same assembly code with or without the '__attribute__((__packed__))'.
$ cat ex.c
struct a {
volatile unsigned short v1;
} __attribute__((__packed__));
extern volatile void *glob_ptr;
void test(void)
{
struct a *ptr = (struct a *) glob_ptr;
ptr->v1 = 0xaa;
}
$ arm-elf-gcc -S -O2 ex.c
$ cat ex.s
.file "ex.c"
.text
.align 2
.global test
.type test, %function
test:
@ args = 0, pretend = 0, frame = 0
@ frame_needed = 0, uses_anonymous_args = 0
@ link register save eliminated.
ldr r3, .L2
ldr r2, [r3, #0]
mvn r3, #85
ldrb r1, [r2, #0] @ zero_extendqisi2
strb r3, [r2, #0]
ldrb r1, [r2, #1] @ zero_extendqisi2
add r3, r3, #86
@ lr needed for prologue
strb r3, [r2, #1]
mov pc, lr
.L3:
.align 2
.L2:
.word glob_ptr
.size test, .-test
.ident "GCC: (GNU) 3.4.2 20040718 (prerelease)"
Environment:
System: Linux namsh 2.6.8-rc2 #91 Mon Jul 19 09:05:11 KST 2004 i686 athlon i386 GNU/Linux
Architecture: i686
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: arm-unknown-elf
configured with: ../configure --target=arm-elf --prefix=/usr/GNUARM --program-prefix=arm-elf- --with-gnu-ld --with-gnu-as --disable-shared --enable-languages=c,c++ --without-headers --with-newlib --disable-nls
How-To-Repeat:
Just gerates the assembly code using the given ex.c.
------- Additional Comments From namsh at kldp dot org 2004-07-23 15:01 -------
Fix:
Do not use '__attribute__((__packed__))'.
Instead use '#pragma pack...'
--
Summary: arm-elf-gcc generates wrong-code
Product: gcc
Version: 3.4.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: namsh at kldp dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: arm-unknown-elf
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16691