[cfe-dev] extra CFGImplicitDtor elements in CFG

Ben Liblit via cfe-dev cfe-dev at lists.llvm.org
Sun May 21 08:55:44 PDT 2017


I am using Clang tooling libraries to build a control-flow graph for C++ 
code.  I need this CFG to accurately reflect all implicit calls to 
destructors, so I have set both the AddImplicitDtors and 
AddTemporaryDtors CFG build options.  Unfortunately, this results in a 
CFG with *extra* CFGImplicitDtor items that do not correspond to actual 
destructor calls in the generated code.

Consider the attached C++11 (or later) test program, "test.cc", with a 
"noisy" destructor.  When run, this program prints "destroy" three 
times.  However, its CFG includes two CFGTemporaryDtor elements plus two 
CFGAutomaticObjDtor elements.  So I have a CFG that shows four 
destructor calls when only three will take place.  (The second attached 
file, "dump-main-cfg.cc", is a bare-bones Clang-based CFG dumping tool 
used here to help reproduce the problem.)

If I comment out lines in main(), leaving only "give();" and the return, 
then I have one "destroy" printed and one CFGTemporaryDtor in the CFG. 
Good.

If instead I leave only "Base base1;" and the return, then I have one 
"destroy" printed and one CFGAutomaticObjDtor in the CFG.  Also good.

If instead I leave only "Base base2(give());" and the return, then I 
have one "destroy" printed and both one CFGTemporaryDtor *and* one 
CFGAutomaticObjDtor in the CFG.  Not good.  :-(

How can I suppress, remove, recognize, or otherwise filter out the extra 
CFGImplicitDtor in cases like "Base base2(give());"?  Is there some 
property I can check of the CFGTemporaryDtor and/or CFGAutomaticObjDtor 
instances to determine which ones will turn into real destructor calls 
and which will not?

Many thanks,
Ben
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.cc
Type: text/x-c++src
Size: 197 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170521/3876eef8/attachment.cc>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dump-main-cfg.cc
Type: text/x-c++src
Size: 2779 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170521/3876eef8/attachment-0001.cc>


More information about the cfe-dev mailing list