This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/60700] New: missing dependency between %ax and %eax when compiling 32bit on 64bit
- From: "yzhou61 at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 28 Mar 2014 17:46:54 +0000
- Subject: [Bug c/60700] New: missing dependency between %ax and %eax when compiling 32bit on 64bit
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60700
Bug ID: 60700
Summary: missing dependency between %ax and %eax when compiling
32bit on 64bit
Product: gcc
Version: 4.8.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: yzhou61 at gmail dot com
When compiling with -m32 on a 64bit machine, gcc is generating wrong code for
the following snippet. The dependencies between %ax and %eax seems to have been
dropped, causing the memset to use the wrong value. Please fix. Thanks.
$ cat repro.c
#include <stdlib.h>
#include <string.h>
extern int foo(void);
void *g = (void *)1;
struct st {
char data[36]; // must be greater than 32
};
int repro(struct st **out)
{
int status = 0;
*out = NULL;
status = foo();
if (status != 0) {
return status;
}
if (NULL == g) {
status = 999;
return status;
}
*out = (struct st *)malloc(sizeof(struct st));
if (NULL == (*out)) {
status = 42;
return status;
}
memset(*out, 0, sizeof(struct st));
return status;
}
$ gcc -c -o repro.o repro.c -m32 -march=i686 -O3 -I. -Wall -Wextra
-fno-strict-aliasing -fwrapv -fno-aggressive-loop-optimizations -save-temps
$ cat repro.s
.file "repro.c"
.text
.p2align 4,,15
.globl repro
.type repro, @function
repro:
.LFB19:
.cfi_startproc
pushl %edi
.cfi_def_cfa_offset 8
.cfi_offset 7, -8
pushl %esi
.cfi_def_cfa_offset 12
.cfi_offset 6, -12
pushl %ebx
.cfi_def_cfa_offset 16
.cfi_offset 3, -16
subl $16, %esp
.cfi_def_cfa_offset 32
movl 32(%esp), %ebx
movl $0, (%ebx)
call foo
testl %eax, %eax
jne .L2
movl g, %edx
movw $999, %ax
testl %edx, %edx
je .L2
movl $36, (%esp)
movl %eax, %esi
call malloc
movl %eax, %edx
testl %edx, %edx
movl %eax, (%ebx)
movl $42, %eax
je .L2
movl %esi, %eax
movl $9, %ecx
movl %edx, %edi
rep; stosl
xorl %eax, %eax
.p2align 4,,7
.p2align 3
.L2:
addl $16, %esp
.cfi_def_cfa_offset 16
popl %ebx
.cfi_restore 3
.cfi_def_cfa_offset 12
popl %esi
.cfi_restore 6
.cfi_def_cfa_offset 8
popl %edi
.cfi_restore 7
.cfi_def_cfa_offset 4
ret
.cfi_endproc
.LFE19:
.size repro, .-repro
.globl g
.data
.align 4
.type g, @object
.size g, 4
g:
.long 1
.ident "GCC: (GNU) 4.8.2"
.section .note.GNU-stack,"",@progbits
$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.8.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ./configure
Thread model: posix
gcc version 4.8.2 (GCC)