bool tell_endian() {
unsigned x = 1;
return *(char*)&x;
}
g++ 3.4.2 produces:
00000000 <_Z11tell_endianv>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: b8 01 00 00 00 mov $0x1,%eax
8: c9 leave
9: c3 ret
g++ 4.0.0 produces:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 83 ec 10 sub $0x10,%esp
6: c7 45 fc 01 00 00 00 movl $0x1,0xfffffffc(%ebp)
d: 31 c0 xor %eax,%eax
f: 80 7d fc 00 cmpb $0x0,0xfffffffc(%ebp)
13: 0f 95 c0 setne %al
16: c9 leave
17: c3 ret
compile line:
g++ -O3 -c -o endian_test.o endian_test.cpp
--
Summary: Runtime endian-ness check is no longer optimized out.
Product: gcc
Version: 4.0.2
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: rtl-optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: atgraham at gmail dot com
GCC host triplet: linux-x86-elf
GCC target triplet: linux-x86-elf
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26069