how to see in AST fields destruction

Hello,

How can I find by AST visitor for which fields destructors are called?

for the following code:
struct WithDestr {
int *i;

WithDestr() : i(nullptr) { }

virtual ~WithDestr() { delete i; }
};

struct Other {
WithDestr d;
long *ptr;
Other() { }
virtual ~Other() { delete ptr; }
};

In AST I see only the construction of field d, but do not see anywhere destruction of d.

-CXXRecordDecl 0x9130050 <line:13:3, line:18:3> line:13:10 struct Other definition

-CXXRecordDecl 0x9130100 <col:3, col:10> col:10 implicit referenced struct Other
-FieldDecl 0x9130160 <line:14:5, col:15> col:15 d ‘struct WithDestr’
-FieldDecl 0x91301c0 <line:15:5, col:11> col:11 referenced ptr 'long * ’
-CXXConstructorDecl 0x9130240 <line:16:5, col:15> col:5 Other ‘void (void) attribute((cdecl))’

-CXXCtorInitializer Field 0x9130160 ‘d’ ‘struct WithDestr’
-CXXConstructExpr 0x9176ae8 <col:5> 'struct WithDestr' 'void (void) __attribute__((cdecl))' -CompoundStmt 0x9176b30 <col:13, col:15>
-CXXDestructorDecl 0x9176850 <line:17:5, col:36> col:13 used ~Other ‘void (void) attribute((cdecl)) noexcept’ virtual
-CompoundStmt 0x9176b98 <col:22, col:36> -CXXDeleteExpr 0x9176b80 <col:24, col:31> ‘void’
-ImplicitCastExpr 0x9176b70 <col:31> 'long * ' <LValueToRValue> -MemberExpr 0x9176b50 col:31 'long * ’ lvalue ->ptr 0x91301c0
`-CXXThisExpr 0x9176b40 col:31 'struct Other * ’ this

Thanks!

Vladimir.

Hello,

How can I find by AST visitor for which fields destructors are called?

for the following code:
  struct WithDestr {
    int *i;

    WithDestr() : i(nullptr) { }

    virtual ~WithDestr() { delete i; }
  };

  struct Other {
    WithDestr d;
    long *ptr;
    Other() { }
    virtual ~Other() { delete ptr; }
  };

In AST I see only the construction of field d, but do not see anywhere
destruction of d.

We do not model the implicit member and base destruction actions performed
by a destructor in the AST.

Richard,

Thanks for the quick reply.
May be you can point me to the code in LLVM where I can find the logic I need (find fields which must be implicitly created/destroyed)?
As destructors have to be called for fields, I assume there is such logic.
May be somewhere at AST-of-destructor => IR conversion layer?

Thanks!
Vladimir.

Richard,

Thanks for the quick reply.
May be you can point me to the code in LLVM where I can find the logic I
need (find fields which must be implicitly created/destroyed)?
As destructors have to be called for fields, I assume there is such logic.
May be somewhere at AST-of-destructor => IR conversion layer?

http://llvm.org/svn/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp

Search for "EnterDtorCleanups".

Richard,

EnterDtorCleanups does exactly what I need!

Thanks!
Vladimir.