Bug#470557: smaller testcase for gcc misoptimization bug
Package: gcc-4.2
Version: 4.2.3-2
--- Please enter the report below this line. ---
I have manually reduced the previous testcase (it is 4K now, vs 32K).
The same testcase can be used for both x86_64 and x86(-32).
When I compile with -O3, or -O2 -finline-functions incorrect code is
generated.
$ gcc-4.2 -O2 -finline-functions gcc42_O3_bug.i
$ ./a.out
Aborted
$ gcc-4.2 -O2 gcc42_O3_bug.i
$ ./a.out
$ valgrind ./a.out
....
==11486== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 8 from 1)
.....
$ sh -x ./test.sh gcc42_O3_bug.i
+ gcc-4.3 -fstack-protector-all -O1 -Wfatal-errors -Werror
-Wno-unused gcc42_O3_bug.i -o works3
+ test 0 == 0
+ ulimit -t 1
+ ./works3
+ test 0 == 0
+ gcc-4.2 -Wall -Wfatal-errors -Werror -Wno-unused -O3
gcc42_O3_bug.i -o fails
+ test 0 == 0
+ ulimit -t 1
+ ./fails
./test.sh: line 24: 11426 Aborted ./fails 2>/dev/null
+ test 134 == 134
+ exit 0
If you need more info, please ask.
--- System information. ---
Architecture: amd64
Kernel: Linux 2.6.25-rc4-00134-g84c6f60
Debian Release: lenny/sid
500 unstable www.debian-multimedia.org
500 unstable ftp.iasi.roedu.net
500 testing ftp.iasi.roedu.net
500 gutsy wine.budgetdedicated.com
1 experimental ftp.iasi.roedu.net
--- Package information. ---
Depends (Version) | Installed
=====================================-+-=====================
binutils (>= 2.17cvs20070426) | 2.18.1~cvs20080103-1
cpp-4.2 (= 4.2.3-2) | 4.2.3-2
gcc-4.2-base (= 4.2.3-2) | 4.2.3-2
libc6 (>= 2.7-1) | 2.7-9
libgcc1 (>= 1:4.2.3-2) | 1:4.3.0-1
typedef unsigned long int uint64_t;
void cli_dbgmsg_internal(const char *str,...) {
}
typedef long unsigned int size_t;
extern int memcmp (__const void *__s1, __const void *__s2, size_t __n) __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
extern void abort (void) __attribute__ ((__nothrow__)) __attribute__ ((__noreturn__));
unsigned char data[] = {
0x50, 0x4d, 0x47, 0x4c, 0x38, 0x01, 0x00, 0x00, 0x63, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x01, 0x2f, 0x00, 0x00, 0x00, 0x06, 0x2f, 0x23, 0x42, 0x53, 0x53, 0x43, 0x01, 0x88, 0x90, 0x79, 0x09, 0x08, 0x2f, 0x23, 0x49, 0x44, 0x58, 0x48, 0x44, 0x52, 0x01, 0xc0, };
typedef long int __off_t;
typedef __off_t off_t;
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
uint8_t cli_debug_flag=0, cli_leavetemps_flag;
typedef struct chm_itsf_header_tag {
uint32_t block_len __attribute__ ((packed));
}
chm_itsp_header_t;
typedef struct chm_metadata_tag {
char *m_area;
chm_itsp_header_t itsp_hdr;
off_t chunk_offset;
char *chunk_data;
char *chunk_current;
char *chunk_end;
uint16_t chunk_entries;
}
chm_metadata_t;
int cli_chm_open( chm_metadata_t *metadata);
int cli_chm_prepare_file(int fd, chm_metadata_t *metadata);
static uint64_t read_enc_int(char **start, char *end) {
uint64_t retval=0;
char *current;
current = *start;
do {
retval = (retval << 7) | (*current & 0x7f);
}
while (*current++ & 0x80);
*start = current;
return retval;
}
static int prepare_file(int fd, chm_metadata_t *metadata) {
uint64_t name_len, section;
while (metadata->chunk_entries != 0) {
if (metadata->chunk_current >= metadata->chunk_end) {
}
name_len = read_enc_int(&metadata->chunk_current, metadata->chunk_end);
if (((metadata->chunk_current + name_len) >= metadata->chunk_end) || ((metadata->chunk_current + name_len) < metadata->chunk_data)) {
(!__builtin_expect(!!(cli_debug_flag), 0)) ? (void)0 : cli_dbgmsg_internal("Bad CHM name_len detected\n");
}
metadata->chunk_current += name_len;
section = read_enc_int(&metadata->chunk_current, metadata->chunk_end);
if(section == 47) {
abort();
}
if (section == 1) {
return 0;
}
}
return 0;
}
static int read_chunk(chm_metadata_t *metadata, int fd) {
if (metadata->m_area != ((void *)0)) {
metadata->chunk_data = metadata->m_area + metadata->chunk_offset;
}
metadata->chunk_current = metadata->chunk_data + (0x14);
if (memcmp(metadata->chunk_data, "PMGL", 4) == 0) {
metadata->chunk_entries = (uint16_t)((((uint8_t const *)(metadata->chunk_data))[metadata->itsp_hdr.block_len-2] << 0) | (((uint8_t const *)(metadata->chunk_data))[metadata->itsp_hdr.block_len-1] << 8));
}
return 0;
}
int main() {
int ret;
chm_metadata_t metadata;
ret = cli_chm_open(&metadata);
ret = cli_chm_prepare_file(-1, &metadata);
return 0;
}
int cli_chm_prepare_file(int fd, chm_metadata_t *metadata) {
int retval;
metadata->chunk_entries=0;
do {
if (metadata->chunk_entries == 0) {
if ((retval = read_chunk(metadata, fd)) != 0) {
}
}
retval = prepare_file(fd, metadata);
}
while (retval == 2);
return 0;
}
int cli_chm_open(chm_metadata_t *metadata) {
metadata->m_area = (char*)data;
metadata->itsp_hdr.block_len = 0x0a;
metadata->chunk_offset = 0;
return 0;
}
Reply to: