[cfe-dev] A new builtin: __builtin_stack_pointer()

Richard Smith richard at metafoo.co.uk
Fri Nov 8 11:34:20 PST 2013


On Thu, Nov 7, 2013 at 6:29 PM, Behan Webster <behanw at converseincode.com>wrote:

> On 11/07/13 01:47, Joerg Sonnenberger wrote:
> > On Wed, Nov 06, 2013 at 05:46:43PM -0800, Behan Webster wrote:
> >> Another way would be to introduce a new builtin in parallel to others
> >> like __builtin_return_address(). Essentially adding a
> >> __builtin_stack_pointer() which does what the above code does. The idea
> >> would be to get something like this added to both clang and gcc in order
> >> to make this work across compilers, and across arches.
> > You still haven't said what the intended behavior of this builtin is
> > when the function containing it is inlined.
> The intent in all situations is for it to use the current value in the
> stack pointer register. It doesn't matter whether it is inlined or not.
> It should be the immediate value of R13 on ARM or esp on X86_64 (etc for
> other arches).
>
> The idea is to preclude the need to use ASM to move the value in the
> stack pointer to another register in order to use it in C code (which is
> inefficient).
>
> Essentially I'm looking for a better solution than adding a C symbol
> name to the stack register.
>
> Does that make sense?


Not yet. Why do you want this? What will you do with it? What semantics do
you want the returned pointer to have? How can correct code ever do
anything with this pointer? (Remember that the backend is in principle
allowed to modify the stack pointer at any time, including between the
point where you call this intrinsic and the point where you use its result.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20131108/14972a1e/attachment.html>


More information about the cfe-dev mailing list