lifetime marker for expression-emission temporaries


Due to the missing lifetime markers for temporary allocas, an unreasonable stack size burst was observed ( Using the C code below, you can see the missing lifetime markers for temporary allocas for sret:

/* clang -Wframe-larger-than=1 -o bug bug.c -c -O1 */

struct a {
   int a; int b;
   int c; int d;
   int f; int g;
   int h; int i;

struct a test_callee(void);

int foo() {
   struct a b;
   b= test_callee();
   return 0;

Based on John McCall's comment in Bug34173, the frond-end needs to be improved to properly add lifetime marks :
    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.

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 ?


Tim - you did some work on lifetime markers ~recently ( year or two ago) for POC stack usage? Any ideas on this?

This appears to be a difference between C and C++:

$ clang -S -O1 -Xclang -disable-llvm-passes t.c -emit-llvm -o - | grep lifetime | wc -l

$ clang -S -O1 -Xclang -disable-llvm-passes -x c++ t.c -emit-llvm -o - | grep lifetime | wc -l

The difference is reflected in the AST as well. C:

-BinaryOperator 0x25397f797a8 <line:12:3, col:18> ‘struct a’:‘struct a’ ‘=’

-DeclRefExpr 0x25397f796c0 col:3 ‘struct a’:‘struct a’ lvalue Var 0x25397f79648 ‘b’ ‘struct a’:‘struct a’
-CallExpr 0x25397f79780 <col:6, col:18> 'struct a':'struct a' -ImplicitCastExpr 0x25397f79768 col:6 ‘struct a (*)(void)’
`-DeclRefExpr 0x25397f796e8 col:6 ‘struct a (void)’ Function 0x25397f79460 ‘test_callee’ ‘struct a (void)’


-DeclRefExpr 0x22bcc9fac60 col:3 ‘struct a’:‘struct a’ lvalue Var 0x22bcc9fa870 ‘b’ ‘struct a’:‘struct a’
-MaterializeTemporaryExpr 0x22bcc9fb050 <col:6, col:18> 'const struct a':'const struct a' lvalue -ImplicitCastExpr 0x22bcc9fb038 <col:6, col:18> ‘const struct a’:‘const struct a’
-CallExpr 0x22bcc9fad80 <col:6, col:18> 'struct a':'struct a' -ImplicitCastExpr 0x22bcc9fad68 col:6 ‘struct a (*)(void)’
`-DeclRefExpr 0x22bcc9face8 col:6 ‘struct a (void)’ lvalue Function 0x22bcc9fa680 ‘test_callee’ ‘struct a (void)’

Note the missing MaterializeTemporaryExpr. I suspect that AST node guides the placement of lifetime start/end markers.