This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/33527] New: GCC doesn't protect %edi when using inline assembly
- From: "meng dot yan at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 22 Sep 2007 06:59:35 -0000
- Subject: [Bug c/33527] New: GCC doesn't protect %edi when using inline assembly
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
OS: Ubuntu 7.04
GCC version: 4.2.1
I try to play the inline assembly function. Here I use "rep movsb" to copy a
string.
// Code begin
char input[] = {"GCC Version Number"};
char output[30];
int length = 28;
asm (
"cld\n\t"
"rep movsb"
:
: "c"(length), "S"(input), "D"(output));
printf("%s\n", output);
// Code end
While compiled without "-O", everything is okay. However, if compiled with
"-O", the compiler will generate incorrect code as if the %edi never changes
during the assembly code execution.
Compile with "-S" will see the corresponding generated assembly codes are:
// code begin
# APP
cld
rep movsb
# NO_APP
movl %edi, -4(%esp) # BAD CODE HERE
movl $.LC1, (%esp)
call printf
// code end
The problem is, movsb changes the value of %esi and %edi, and I told the
compiler about this in the "input" section in the asm directive. The compiler
didn't notice this and believe the value of %edi unchanged.
I think this is a bug.
--
Summary: GCC doesn't protect %edi when using inline assembly
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: meng dot yan at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33527