<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Jul 13, 2019 at 3:11 PM Jorg Brown via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Sat, Jul 13, 2019 at 12:40 PM Sanjoy Das via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Samuel,<br>
<br>
You can't expect alloca's to reliably lower to stack pointer<br>
adjustments.  The semantics of alloca is more high level -- it give<br>
you an abstract memory location that lives and dies with the function<br>
frame, but there is no guarantee that it will actually "allocate"<br>
memory from the stack frame.  The compiler may promote the memory to<br>
registers or (theoretically speaking, we don't do this today) even<br>
demote it to a heap allocation.<br></blockquote><div><br></div><div>What?!?</div><div><br></div><div>1) If it gets demoted to a heap allocation, when does the memory ever get freed?  There is no "freea" call, after all.</div><div>2) What alloca documentation are you looking at, that allows for heap allocation?</div><div><br></div><div>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 ( <a href="https://www.phoronix.com/scan.php?page=news_item&px=Linux-Kills-The-VLA" target="_blank">https://www.phoronix.com/scan.php?page=news_item&px=Linux-Kills-The-VLA</a> )</div></div></div></blockquote><div><br>I think Sanjoy was maybe talking in terms of LLVM's alloca intrinsic, rather than the C API. But in any case, the C API seems quite implementable with dynamic memory allocation - the basic API being "The alloca() function allocates size bytes of space in the stack frame of the caller.  This temporary space is automatically freed when the function that called alloca() returns to its caller. - yeah, an implementation could implement that in terms of dynamic memory allocation automatically freed at the end of the function call.<br><br>The fact that it says "in the stack frame of the caller" is perhaps fuzzy enough - we already have things like split stacks - seems plausible we could have dynamically allocated stack frames, or partially dynamically allocated ones - at which point alloca using such a thing would fit the definition.<br><br><br><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div><br></div><div>-- Jorg</div></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>