handling of FIXED_REGISTERS

Ian Lance Taylor ian@wasabisystems.com
Tue Mar 9 21:32:00 GMT 2004


Olatunji Ruwase <tjruwase@transmeta.com> writes:

> I have question regarding the handling of FIXED_REGISTERS in gcc. These 
> are hard registers which are specified by different architectures as not 
> available to the compiler for general allocation. For example "sp" in 
> i386. However while the compiler respects this restriction during 
> register allocation, this restriction is not extended to inline assembly.
> Therefore it is possible to use sp in inline assembly as follows, 
>     register int foo asm("sp") 
> allowing the programmer code to clobber "sp" arbitrarily.
> While I cant think of any useful reason to write code of such nature, I m 
> curious as to why gcc is designed not to reject it.

While I can't think of a way to usefully use "sp" as a register
variable, there are ways to usefully use other fixed registers as
local register variables.  For example, on most PowerPC targets, r2 is
used as the TOC pointer, and is a fixed register.  However, it is
possible to write correct code which uses a register variable to hold
the TOC pointer.

In general, if you use register variables, gcc presumes that you know
what you are doing.  That includes using a fixed register for a
register variable.  gcc shouldn't reject it just because it looks
unwise.

Ian



More information about the Gcc mailing list