[llvm-dev] Avoiding alloca elision
Jorg Brown via llvm-dev
llvm-dev at lists.llvm.org
Sat Jul 13 15:10:33 PDT 2019
On Sat, Jul 13, 2019 at 12:40 PM Sanjoy Das via llvm-dev <
llvm-dev at lists.llvm.org> wrote:
> Hi Samuel,
>
> You can't expect alloca's to reliably lower to stack pointer
> adjustments. The semantics of alloca is more high level -- it give
> you an abstract memory location that lives and dies with the function
> frame, but there is no guarantee that it will actually "allocate"
> memory from the stack frame. The compiler may promote the memory to
> registers or (theoretically speaking, we don't do this today) even
> demote it to a heap allocation.
>
What?!?
1) If it gets demoted to a heap allocation, when does the memory ever get
freed? There is no "freea" call, after all.
2) What alloca documentation are you looking at, that allows for heap
allocation?
As far as I know, if the memory can't be stack-allocated, alloca() is just
supposed to return NULL... though frankly, as far as I can tell alloca is a
nonstandard extension that is implemented differently from one platform to
the next. For that matter, even variable-length arrays in C aren't
guaranteed to work. (C11 made them optional?) And interestingly, Linux
went to the trouble of removing them all (
https://www.phoronix.com/scan.php?page=news_item&px=Linux-Kills-The-VLA )
-- Jorg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190713/e3284702/attachment.html>
More information about the llvm-dev
mailing list