<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>Dear Ksenia,</div><div> <br></div><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">Message: 3<br>
Date: Fri, 10 Apr 2015 16:03:18 +0300<br>
From: Ksenia Dolgorukova <<a href="mailto:der.spiegel.sieht.mich@gmail.com">der.spiegel.sieht.mich@gmail.com</a>><br>
To: <a href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a><br>
Subject: [LLVMdev] Different signatures or smart casting?<br>
Message-ID:<br>
        <<a href="mailto:CALtCODFHh-Y9dreELuiiHt2BXRcmtBSr6LXAzvExhEGoSqPrtw@mail.gmail.com">CALtCODFHh-Y9dreELuiiHt2BXRcmtBSr6LXAzvExhEGoSqPrtw@mail.gmail.com</a>><br>
Content-Type: text/plain; charset=UTF-8<br>
<br>
Hello!<br>
I linked two bitcode files like described below using LTO and find<br>
they are linked fine instead of making an error.<br>
----------<br>
1.bc<br>
----------<br>
...<br>
define i32 @main(i32 %argc, i8** %argv) #0 {<br>
entry:<br>
...<br>
%call = call i32 @_Z1aj(i64 2)<br>
...<br>
}<br>
declare i32 @_Z1aj(i64) #1<br>
...<br>
<br>
----------<br>
2.bc<br>
----------<br>
...<br>
define i32 @_Z1aj(i32 %b) #0 {<br>
entry:<br>
...<br>
}<br>
...<br>
<br>
----------<br>
<br>
In the first file function "_Z1aj" is declared as having i64 argument,<br>
whereas in the second file the function "_Z1aj" is described as having<br>
i32 argument!<br>
<br>
Are function signatures different?<br>
How does LLVM cast them?<br>
Could it be a bug?<br></blockquote><div><br></div><div><br></div><div>After playing around a little bit, I found this might actually be a feature of the C language. And please correct me if I'm wrong. For example, the following actually gets compiled with clang as well as gcc:</div><div><br></div><div>// main.c</div><div><div>#include <stdio.h>                                                                                       </div><div>void foo(char c);                                                                       </div><div>int main()              </div><div>{                                                                                                </div><div>    foo(100);           </div><div>    return 0;            </div><div>} </div></div><div><br></div><div>// foo.c</div><div>#include <stdio.h></div><div><div>void foo(int c)                                                                    </div><div>{</div><div>    printf("The param is %d\n", c); </div><div>}  </div></div><div><br></div><div><br></div><div>$ gcc hello.c foo.c</div><div><br></div><div>Although the declaration and definition for foo has different parameter types, the foo.c and main.c compiled successfully. I think this might be the 'feature' of the linker, since C object files exposes function names only. This won't compiler if you're using clang++ or g++.</div><div><br></div><div>The corresponding IR is following:</div><div><br></div><div>;; main.ll</div><div><br></div><div>declare void @foo(i8 signext) #1<br></div><div><br></div><div>;; foo.ll</div><div><br></div><div>define void @foo(i32 %c) #0 {<br></div><div>  ...</div><div>}</div><div><br></div><div><br></div><div>Not only so, the following C code also compiles with gcc-4.9 and clang-3.5:</div><div><br></div><div>// main.c</div><div><br></div><div>void foo(char c);<br></div><div><br></div><div>// foo.c</div><div>void foo(int c, int d, int e)</div><div>{</div><div>    printf("The param is %d, %d, %d\n", c, d, e);</div><div>}</div><div><br></div><div>The running result is:</div><div><br></div><div>The param is 100, 911150376, 911150392<br></div><div><br></div><div>The last two numbers, I believe, represents memory on the stack, cause that's where the C functions are reading parameters from.</div><div><br></div><div>Correct me if you found somewhere I was wrong.</div><div><br></div><div><br></div><div>Regards,</div><div>Kevin</div><div><br></div><div> </div><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">
--<br>
Best regards, Ksenia<br>
<br><br></blockquote></div>
</div></div>