<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><br><div><div>On Jan 21, 2010, at 11:03 AM, Sanjiv Gupta wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Duncan Sands wrote:<br><blockquote type="cite">Hi,<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><blockquote type="cite">Bitcode generated by llvm-ld with –disable-opt and –basiccg options is:<br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">...<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><blockquote type="cite">My point is why is the call to foo not resolved correctly in llvm-ld. <br></blockquote></blockquote><blockquote type="cite"><blockquote type="cite"><br></blockquote></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite">Resolving an call to a direct call is an optimization.  But you turned all<br></blockquote><blockquote type="cite">optimizations off.<br></blockquote><blockquote type="cite"><br></blockquote><blockquote type="cite"><br></blockquote>BTW, why do clang generates an indirect call in the first place for the <br>program given in the original post? Does c99 tell us to generate an <br>indirect call when the prototype is like this<br>  void foo(); <br><br>?<br></div></blockquote></div><br><div>C99 doesn't tell us to generate an indirect call, but it does tell us that we can't make assumptions about the actual signature of foo (other than the return type).  That matters here because it means we have no idea what that signature  is when we're generating code for main().  You could easily write:</div><div><br></div><div>void foo();</div><div>int main() {</div><div>  foo();</div><div>}</div><div><br></div><div>void foo(int i) {</div><div>}</div><div><br></div><div>If we codegenned this as a direct call, we'd get:</div><div><br></div><div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 12pt; font-family: 'Times New Roman'; "><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: 'Courier New'; ">define i32 @main() nounwind {<o:p></o:p></span></font></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 12pt; font-family: 'Times New Roman'; "><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: 'Courier New'; ">entry:<o:p></o:p></span></font></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 12pt; font-family: 'Times New Roman'; "><span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px; ">  call void (...)* @foo()</span></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 12pt; font-family: 'Times New Roman'; "><span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px; ">  ret i32 0</span></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 12pt; font-family: 'Times New Roman'; "><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: 'Courier New'; ">}<o:p></o:p></span></font></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 12pt; font-family: 'Times New Roman'; "><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: 'Courier New'; "><o:p> </o:p></span></font></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 12pt; font-family: 'Times New Roman'; "><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: 'Courier New'; ">define void @foo(i32) nounwind {<o:p></o:p></span></font></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 12pt; font-family: 'Times New Roman'; "><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: 'Courier New'; ">entry:<o:p></o:p></span></font></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 12pt; font-family: 'Times New Roman'; "><span class="Apple-style-span" style="font-family: 'Courier New'; font-size: 13px; ">  ret void</span></div><div style="margin-top: 0in; margin-right: 0in; margin-bottom: 0.0001pt; margin-left: 0in; font-size: 12pt; font-family: 'Times New Roman'; "><font size="2" face="Courier New"><span style="font-size: 10pt; font-family: 'Courier New'; ">}<o:p></o:p></span></font></div><div><font class="Apple-style-span" face="'Courier New'" size="3"><span class="Apple-style-span" style="font-size: 13px;"><span class="Apple-style-span" style="font-family: Helvetica; font-size: medium; "><div><br></div><div>This is a type error, because @foo is not of type void (...)*.</div><div><br></div><div>We could work around this specific problem by delaying code-generation for @main until we see the definition of foo, but that still wouldn't work for e.g. link-time optimization.</div><div><br></div><div>John.</div></span></span></font></div></div></body></html>