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?
test.cc (197 Bytes)
dump-main-cfg.cc (2.71 KB)