Hi John and Matthieu,<div><br></div><div>Thank you very much for the details :)</div><div><br></div><div>~Umesh<br><br><div class="gmail_quote">On Fri, Feb 3, 2012 at 1:07 AM, John McCall <span dir="ltr"><<a href="mailto:rjmccall@apple.com">rjmccall@apple.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div class="im"><div>On Feb 2, 2012, at 10:59 AM, Matthieu Monrocq wrote:</div></div>
<blockquote type="cite"><div class="gmail_quote"><div class="im">Le 2 février 2012 12:48, Umesh Kalappa <span dir="ltr"><<a href="mailto:umesh.kalappa0@gmail.com" target="_blank">umesh.kalappa0@gmail.com</a>></span> a écrit :<br>
<blockquote class="gmail_quote" style="margin-top:0px;margin-right:0px;margin-bottom:0px;margin-left:0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class="gmail_quote">Hi There ,<br><div class="gmail_quote"><div><br></div><div>I'm new  to Clang   and please pardon me ..if you guys  feel that ,the below question is very basic :) </div><div><br></div><div>Here i go ,compiled the below sample with clang i.e <b>clang enum.c -S -emit-llvm</b> and  respective files are </div>





<div><br></div><div><div>$ cat enum.c</div><div>int main()</div><div>{</div><div> enum type{one=1,two,three} s;</div><div> s = one;</div><div> return s;</div><div>}</div></div><div><br></div><div><div>$ cat enum.s</div><div>





; ModuleID = 'enum.c'</div><div>target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32-S32"</div><div>target triple = "i386-pc-cygwin"</div>





<div><br></div><div>define i32 @main() nounwind {</div><div>  %1 = alloca i32, align 4</div><div>  %s = alloca i32, align 4</div><div>  store i32 0, i32* %1</div><div>  store i32 1, i32* %s, align 4</div><div>  %2 = load i32* %s, align 4</div>





<div>  ret i32 %2</div><div>}</div></div><div><br></div><div><b>Question :</b> Why there is  extra 4 bytes on stack i.e  <b>"%1 = alloca i32, align 4"</b>  ???</div><div><br></div><div>Note : Please note that the  LLVM transformation will free away those extra space ,But still like to know why Clang at first shot introduces those extra spaces ?? </div>


<div><br></div></div></div></blockquote></div><div class="im"><div>It looks to me like %1 is allocated just in case we would need it for a "ret i32 %1" instruction at the end of main (since it's not mandatory for the user to define it). The "store i32 0, i32* %1" seems to agree with this understanding, as 0 is the default return value.<br>
</div></div></div></blockquote></div><br><div>Yes.  We allocate an implicit local variable to hold the return value;  return statements then just initialize the return slot and jump to the epilogue, where the slot is loaded and returned.  We don't use a phi because the control flow for getting to the epilogue is not necessarily as simple as a simple branch, due to cleanups in local scopes (like C++ destructors).</div>
<div><br></div><div>Implicit return values like main's are handled with an implicit store in the prologue.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>John.</div></font></span></div></blockquote>
</div><br></div>