<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Oct 8, 2015 at 7:15 AM, Tim Northover via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">On 8 October 2015 at 03:31, Joerg Sonnenberger <<a href="mailto:joerg@britannica.bec.de">joerg@britannica.bec.de</a>> wrote:<br>
> I think we are talking about two different things here. What I am<br>
> advocating is that callsite and function signature must have matching<br>
> ABI. I think we already enforce that for things like argument type, so<br>
> enforcing sret doesn't seem to be any different. I am not saying that<br>
> you should not be able to override it via manual bitcasting, but that's<br>
> a completely different topic. If you do that, you are on your own.<br>
<br>
</span>Unfortunately the two aren't separable because the sret isn't part of<br>
the function's type. You can't even write down a bitcast that adds or<br>
removes it:<br>
<br>
$ cat simple.ll<br>
define void @foo(void(i8*)* %fn) {<br>
  %tst = bitcast void(i8*)* %fn to void(i8* sret)*<br>
  ret void<br>
}<br>
$ opt -verify simple.ll -S<br>
opt: simple.ll:2:41: error: argument attributes invalid in function type<br>
  %tst = bitcast void(i8*)* %fn to void(i8* sret)*<br>
<br>
So if you ban mismatches at call sites, you're banning the casts too.<br></blockquote><div><br></div><div>I agree. Maybe a different analogy based on an FAQ[1] will work. sret is similar to the function calling convention. The function calling convention is, for reasons that I don't agree with, not part of the function type. Therefore the verifier accepts direct calls to functions with mismatched calling conventions, because it's not a type mismatch. The optimization passes, however, will transform that call to unreachable.</div><div><br></div><div>I argue the same applies to sret. Because the verifier does not reject it, we cannot assert on a mismatch later. We have to either make sret part of the type system, so that mismatches cannot occur without a cast, or we have to silently accept it and generate code that's probably incorrect.</div><div><br></div><div>[1] <a href="http://llvm.org/docs/FAQ.html#why-does-instcombine-simplifycfg-turn-a-call-to-a-function-with-a-mismatched-calling-convention-into-unreachable-why-not-make-the-verifier-reject-it">http://llvm.org/docs/FAQ.html#why-does-instcombine-simplifycfg-turn-a-call-to-a-function-with-a-mismatched-calling-convention-into-unreachable-why-not-make-the-verifier-reject-it</a></div></div></div></div>