<div dir="ltr">This appears to be a difference between C and C++:<div><div><br></div><div>$ clang -S -O1 -Xclang -disable-llvm-passes t.c -emit-llvm -o - | grep lifetime | wc -l</div><div>4</div><div><br></div><div>$ clang -S -O1 -Xclang -disable-llvm-passes -x c++ t.c -emit-llvm -o - | grep lifetime | wc -l</div><div>16</div></div><div><br></div><div>The difference is reflected in the AST as well. C:</div><div><div>    |-BinaryOperator 0x25397f797a8 <line:12:3, col:18> 'struct a':'struct a' '='</div><div>    | |-DeclRefExpr 0x25397f796c0 <col:3> 'struct a':'struct a' lvalue Var 0x25397f79648 'b' 'struct a':'struct a'</div><div>    | `-CallExpr 0x25397f79780 <col:6, col:18> 'struct a':'struct a'</div><div>    |   `-ImplicitCastExpr 0x25397f79768 <col:6> 'struct a (*)(void)' <FunctionToPointerDecay></div><div>    |     `-DeclRefExpr 0x25397f796e8 <col:6> 'struct a (void)' Function 0x25397f79460 'test_callee' 'struct a (void)'</div></div><div><br></div><div>C++:</div><div><div>    |   |-DeclRefExpr 0x22bcc9fac60 <col:3> 'struct a':'struct a' lvalue Var 0x22bcc9fa870 'b' 'struct a':'struct a'</div><div>    |   `-MaterializeTemporaryExpr 0x22bcc9fb050 <col:6, col:18> 'const struct a':'const struct a' lvalue</div><div>    |     `-ImplicitCastExpr 0x22bcc9fb038 <col:6, col:18> 'const struct a':'const struct a' <NoOp></div><div>    |       `-CallExpr 0x22bcc9fad80 <col:6, col:18> 'struct a':'struct a'</div><div>    |         `-ImplicitCastExpr 0x22bcc9fad68 <col:6> 'struct a (*)(void)' <FunctionToPointerDecay></div><div>    |           `-DeclRefExpr 0x22bcc9face8 <col:6> 'struct a (void)' lvalue Function 0x22bcc9fa680 'test_callee' 'struct a (void)'</div></div><div><br></div><div>Note the missing MaterializeTemporaryExpr. I suspect that AST node guides the placement of lifetime start/end markers.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 21, 2017 at 8:48 AM, via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
Due to the missing lifetime markers for temporary allocas, an unreasonable stack size burst was observed (<a href="https://bugs.llvm.org/show_bug.cgi?id=34173" rel="noreferrer" target="_blank">https://bugs.llvm.org/show_bu<wbr>g.cgi?id=34173</a>). Using the C code below, you can see the missing lifetime markers for temporary allocas for sret:<br>
<br>
/* clang -Wframe-larger-than=1 -o bug bug.c -c -O1 */<br>
<br>
struct a {<br>
  int a; int b;<br>
  int c; int d;<br>
  int f; int g;<br>
  int h; int i;<br>
};<br>
<br>
struct a test_callee(void);<br>
<br>
int foo() {<br>
  struct a b;<br>
  b= test_callee();<br>
  b= test_callee();<br>
  b= test_callee();<br>
  b= test_callee();<br>
  b= test_callee();<br>
  b= test_callee();<br>
  return 0;<br>
}<br>
<br>
Based on John McCall's comment in Bug34173, the frond-end needs to be improved to properly add lifetime marks :<br>
   Clang's adoption of lifetime markers has been rather piecemeal, especially for expression-emission temporaries like this. To do this properly, I think we'd need to honor full-expression lifetime implicitly rather than relying on ExprWithCleanups.<br>
<br>
Honestly, I don't have much experience in the front-end and I have other issues to handle in priority. Is there anyone who can volunteer for this issue ?<br>
<br>
Thanks,<br>
Jun<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
-- <br>
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.<br>
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.<br>
______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
</font></span></blockquote></div><br></div>