[cfe-dev] [Bug] Wrong Exception Handling : Destructor not called immediately

suyog sarda sardask01 at gmail.com
Mon Apr 21 12:21:11 PDT 2014


Ok. sorry for my silly question above. i tested the code for the question i
had, and it seems that destructor of all temporaries
as well as other objects created before the current line are being called
when exception occurs, except the destructor of the
outermost object.

>From the discussion in the link shared in the previous mail and the results
of the test case, i conclude that for
clang, outermost object *temp *of class *b *is not considered constructed
until all the inner temporaries are destroyed.

Since the outermost 'temp' is considered yet to be constructed fully, its
destructor is not pushed in '*EHStack*'.
As a result whenever exception occurs in the destructor of temporaries, the
EHStack does not contain destructor of outermost
object and hence its cleanup doesn't take place.

Please correct me if i am wrong? Also, while debugging i came across,
following piece of code,

*void CodeGenFunction::EmitCXXTryStmt
<http://clang.llvm.org/doxygen/classclang_1_1CodeGen_1_1CodeGenFunction.html#a079ab0affd32c3e7d992d8421776b732>(const
CXXTryStmt <http://clang.llvm.org/doxygen/classclang_1_1CXXTryStmt.html>
&S <http://clang.llvm.org/doxygen/AnalysisBasedWarnings_8cpp.html#a33dc45a03958a0bf07b5da2dec4db648>)
{
        EnterCXXTryStmt
<http://clang.llvm.org/doxygen/classclang_1_1CodeGen_1_1CodeGenFunction.html#ae064b29757ae2b6085d4df62ea2df530>(S);
        EmitStmt
<http://clang.llvm.org/doxygen/classclang_1_1CodeGen_1_1CodeGenFunction.html#ab625dabfdcc8082335d64c4cbd009ef0>(S.getTryBlock
<http://clang.llvm.org/doxygen/classclang_1_1CXXTryStmt.html#a0b14fc308d0e5f78e4f2bd425fc308da>());
        ExitCXXTryStmt
<http://clang.llvm.org/doxygen/classclang_1_1CodeGen_1_1CodeGenFunction.html#ac1f782050e59094db58fbbd1b9e3f8c1>(S);
 }*



which after several function calls in between leads me to below (for
init-temp1.C test code) :

*CodeGenFunction::emitAutoVarTypeCleanup*
{
.....




*// Use an EH cleanup in array destructors iff the destructor itself  // is
being pushed as an EH cleanup.  bool useEHCleanup = (cleanupKind &
EHCleanup);  EHStack.pushCleanup<DestroyObject>(cleanupKind, addr, type,
destroyer,                                     useEHCleanup);*
}

At this point the destructor is pushed to EHStack. When i traced the code
for init-temp1.C, i hit the *EHStack.pushcleanup *function above*, *still
the destructor of outermost object is not being called.

Can someone please help me if i am looking at right place? If my analysis
for clang is right - outermost object not considered created until
innermost temporaries are destroyed - where should i look to correct this
problem?

If by design, clang doesn't consider outermost object to be created until
inner temporaries are destroyed, would this be a resource leak (i don't
think it is leak, as the object is yet to be constructed, hence no
destruction required)?

Your help would be highly appreciated.


-- 
With regards,
Suyog Sarda
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140422/0d5c5499/attachment.html>


More information about the cfe-dev mailing list