Hi,<div><br></div><div>First of all, compiler version:</div><div><div>clang -v</div><div>Apple clang version 3.1 (tags/Apple/clang-318.0.45) (based on LLVM 3.1svn)</div><div>Target: x86_64-apple-darwin11.3.0</div><div>Thread model: posix</div>

<div><div></div></div></div><div><div><br></div><div><br></div><div>I am migrating an old C++ library to use clang, and it has some a stack size checking code, the essential part is like below: </div><div><br></div><div>
unsigned char* init_stack_base; //this is set before calling recurse()</div>
<div><br></div><div>void recurse() {<br>      unsigned char buf[0x100];</div><div>      unsigned long long bytes_used;</div><div>      bytes_used = (init_stack_base - buf);</div><div>      if (bytes_used > STACK_LIMIT + 0x100)</div>

<div>            my_assert(); // void my_assert();</div><div>      recurse();</div><div>}</div><div><br></div><div>The variable size for  one recurse() call is sizeof(buf) + sizeof(bytes_used). which is 256+8= 264, of course I need consider the stack is aligned with 16bytes, so it will be 0x110 (272).  This is exactly the number I got from LLVM GCC 4.2. </div>

<div><br></div><div>The interesting thing is, when I switch to clang,  it reserves 0x120 bytes for variables. As a result, the code now asserts because the STACK_LIMIT is defined  with the assumption above.</div><div><br>

</div><div>Anyone can explain why clang needs alloc extra 16 bytes stack for the same code?</div><div><br></div><div>If you need test it, I pasted the test program at:</div><div><a href="http://snipt.org/ufDi0">http://snipt.org/ufDi0</a></div>
<div><br></div><div>thanks!</div><div><br></div><div><div>-- <br>Yingshen(Jonny) Yu<br><br>
</div></div></div>