Bug 37613 - probelm with optmization and local variable stored in an asm register
Summary: probelm with optmization and local variable stored in an asm register
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-09-22 11:17 UTC by daniel.diaz
Modified: 2008-09-22 14:08 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description daniel.diaz 2008-09-22 11:17:20 UTC
in this simple function

bug.c:
void restore() {
  register long reg_ebx asm ("ebx");
  reg_ebx = saved_ebx;
}


$ gcc -v
Utilisation des specs internes.
Target: i386-redhat-linux
Configuré avec: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --enable-plugin --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-cpu=generic --build=i386-redhat-linux
Modèle de thread: posix
gcc version 4.3.2 20080905 (Red Hat 4.3.2-3) (GCC) 

$ uname -a
Linux lima.univ-paris1.fr 2.6.24-0.83.rc5.fc9 #1 SMP Tue Dec 11 12:04:08 EST 2007 i686 i686 i386 GNU/Linux

$ gcc -O -S  -ffixed-ebx -fomit-frame-pointer bug.c
$ cat bug.c

restore:
	rep
	ret
	.size	restore, .-restore
	.comm	saved_ebx,4,4

the function is empty: the assignment to reg_ebx has been discarded (because considered as a local variable). In the presence of asm it should be kept.
It is OK if -O is not given.

Maybe there is a way do it differently (btw I cannot declare the var as global nor static in my application).
Comment 1 Richard Biener 2008-09-22 11:27:58 UTC
reg_ebx is obviously unused in your function so the assignment is DCEd.  I guess
what you try to do is not really possible with C.
Comment 2 daniel.diaz 2008-09-22 14:08:15 UTC
Richard Guenther says it is impossible in C... In C maybe but not in GNU C :-)
This worked perfectly under older versions (may gcc 3.x.x) and it is a pitty if this feature is lost now.