[cfe-dev] lifetime marker for expression-emission temporaries

Reid Kleckner via cfe-dev cfe-dev at lists.llvm.org
Tue Aug 22 18:17:18 PDT 2017


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
4

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

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)'
<FunctionToPointerDecay>
    |     `-DeclRefExpr 0x25397f796e8 <col:6> 'struct a (void)' Function
0x25397f79460 'test_callee' 'struct a (void)'

C++:
    |   |-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' <NoOp>
    |       `-CallExpr 0x22bcc9fad80 <col:6, col:18> 'struct a':'struct a'
    |         `-ImplicitCastExpr 0x22bcc9fad68 <col:6> 'struct a (*)(void)'
<FunctionToPointerDecay>
    |           `-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.

On Mon, Aug 21, 2017 at 8:48 AM, via cfe-dev <cfe-dev at lists.llvm.org> wrote:

> Hi,
>
> Due to the missing lifetime markers for temporary allocas, an unreasonable
> stack size burst was observed (https://bugs.llvm.org/show_bug.cgi?id=34173).
> 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();
>   b= test_callee();
>   b= test_callee();
>   b= test_callee();
>   b= test_callee();
>   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 ?
>
> Thanks,
> Jun
>
>
> --
> Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
> Technologies, Inc.
> Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux
> Foundation Collaborative Project.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170822/04cc964e/attachment.html>


More information about the cfe-dev mailing list