[llvm-dev] Avoiding alloca elision

Samuel Williams via llvm-dev llvm-dev at lists.llvm.org
Sat Jun 29 06:31:39 PDT 2019


Hello

I'm implementing stack copying coroutines. It's an interesting challenge.
When we use setjmp/longjmp to move between stacks, we must make sure that
restoring the stack doesn't blow away the current stack frame before
calling longjmp.

To do that, we check how big the stack we are restoring is, and use alloca
to push the current stack frame beyond that. It works but when I add "-O3"
the alloca is elided and it fails again.

I managed to avoid this by using the resulting buffer in an operation the
compiler can't elide. But I was wondering, is there an __attribute__ or
other mechanism by which I can tell the compiler: Don't elide this
statement even if the result is unused.

Here is the code:
https://github.com/ioquatix/ruby/blob/3fd9102cb885858038d6a29071acecef78e6d6a5/coroutine/copy/Context.c#L36-L80

You can see on line 57, I forced compiler to use the result of the alloca.
If I remove this, it fails because alloca is not invoked.

Any help/suggestions appreciated.

Kind regards,
Samuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190630/8bf94bf9/attachment.html>


More information about the llvm-dev mailing list