I think the latest patch is good, Eli, do you have any concerns before we move forward and start working on the Clang side of things?<div><br></div><div>Ben, one think we might do to help address Eli's concerns is add some scare notes to the documentation for these intrinsics saying that they are extremely dangerous, etc etc.</div>
<div><br></div><div>Once we get the Clang side rigged up, it'll be a lot easier to do testing...</div><div>-Chandler<br><div><br><div class="gmail_quote">On Tue, May 15, 2012 at 12:03 PM, Chandler Carruth <span dir="ltr"><<a href="mailto:chandlerc@google.com" target="_blank">chandlerc@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_quote"><div><div class="h5">On Tue, May 15, 2012 at 11:36 AM, Eli Friedman <span dir="ltr"><<a href="mailto:eli.friedman@gmail.com" target="_blank">eli.friedman@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Tue, May 15, 2012 at 10:03 AM, Benjamin Kramer<br>
<div><<a href="mailto:benny.kra@googlemail.com" target="_blank">benny.kra@googlemail.com</a>> wrote:<br>
><br>
> On 15.05.2012, at 18:16, Chandler Carruth wrote:<br>
><br>
>> On Tue, May 15, 2012 at 9:08 AM, Benjamin Kramer <<a href="mailto:benny.kra@googlemail.com" target="_blank">benny.kra@googlemail.com</a>> wrote:<br>
>> This will be used to implement __builtin_va_arg_pack[len] in clang (PR7219).<br>
>><br>
>> Awesome, thanks for working on this...<br>
>><br>
>> Since this is used to model a pretty crazy gcc extension (used by glibc) we have<br>
>> to expand the intrinsics in the inliner. When it replaces a vararg call site with<br>
>> a copy of the function another pass over all instructions is performed which<br>
>> replaces any pack intrinsics with the values from the call site. There are some<br>
>> rather narrow requirements where the intrinsics can occur, documented in LangRef<br>
>> and enforced by the verifier.<br>
>><br>
>> This patch has two other side effects:<br>
>> - DAE is not allowed to remove varargs if a va_pack intrinsic is used.<br>
>> - Inliner can now inline vararg functions iff they don't use va_start. This can<br>
>>  happen if DAE doesn't remove the varargs because there is a va_pack intrinsic<br>
>>  or if the AlwaysInliner tries to inline the function.<br>
>><br>
>><br>
>> I'm pretty OK wit this strategy. It actually has some other interesting artifacts I'd like to explore later. Specifically, I think we can generalize this to allow inlining of varargs functions when the va_start is in dead code...<br>


<br>
</div>I'm actually mildly concerned about this strategy: the LLVM IR inliner<br>
can't actually reason correctly about the ABI rules for a varargs<br>
call, and will therefore screw up if you try to pass anything<br>
complicated (_Complex, structs) through the varargs list.  This might<br>
not matter in practice if it isn't used for anything other than the<br>
printf and scanf families of functions, but it's still worth thinking<br>
about.</blockquote><div><br></div></div></div><div>I share your concerns here regarding the pack and pack_len builtins... However, I think in the extremely limited context they are used, this is safe.</div><div><br></div>
<div>The idea is that these builtins can only be used inside of some other vararg function, and the only arguments we move from the outer call to the inner are ones that would already have gone through Clang's vararg lowering. The goal seems specifically to re-use the way that the outer call is lowered when setting up the inlined inner call.</div>

<div><br></div><div>I've been trying to think of a construct that breaks this, but so far I can't come up with any... </div></div>
</blockquote></div><br></div></div>