[cfe-dev] Throwing exceptions from temporary object's destructor

Matthieu Monrocq matthieu.monrocq at gmail.com
Mon Sep 3 09:23:38 PDT 2012


On Mon, Sep 3, 2012 at 7:46 AM, SENTHIL KUMAR THANGAVELU <
senthil.t at samsung.com> wrote:

>  Hello all,
>    I had looked into bug 12306 http://llvm.org/bugs/show_bug.cgi?id=12306specifically init-temp1.C (attached test case in mail). There is a problem
> with the following snippet, when compiled with clang 3.1 release
>
>      try {
>        b tmp(f (a(), a()));
>
>        g();
>      }
>      catch (...) {}
>
>      In expression "b tmp(f (a(), a()));" if first temporary object a()
> throws an exception, object "tmp" is not cleaned up. Issue seems to be
> absence of ehcleanup entry for object "tmp" in the EhStack, when
> PopCleanupBlocks is called via VisitExprWithCleanups. Cleanup code for the
> 2 temporary "a()" objects are emitted when VisitExprWithCleanups node is
> visited, whereas autovar object "tmp"'s cleanup code is emitted by lexical
> scope cleaning. Association between the cleanup of temporary a() objects
> and the cleanup of auto var decl depending on the temporary objects is
> missing.
>
>      I tried pushing object "tmp" cleanup entry (kind == EHCleanup) on top
> of EhStack when a() objects' cleanup entries are also present in the
> EHStack. I did this to check whether cleanup code for freeing "tmp" will be
> emitted, when first temporary's destructor threw an exception. After my
> code change object tmp was destroyed when object a()'s destructor threw an
> exception. There were 2 problems with the generated code.
>
>      1) Second temporary object a() was destroyed before object "tmp" got
> destroyed
>      2) Apart from the destructor, even if the constructor of a() failed,
> call to cleanup "tmp" was emitted via landingpad
>
>      I could see that the landing pads generated are symmetric for an
> object's constructor and destructor e.g if an object's constructor had
> lpad3 as landing pad, its destructor also had lpad3 as landing pad. In case
> of temporary object cleanup I need some functionality like if constructor
> threw exception use landing pad lpad_X. If destructor threw then use
> landing pad lpad_Y. If this has been done before, any suggestions on which
> part of code can I refer to for an example implementation? All other
> general comments on other approaches to fix this issue are also welcome.
>
>  Regards
>  Senthil Kumar
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
> I have a big doubt suddenly: what do you mean by cleanup ?

If a call to `a()` throws, then `f` is never called, and thus `tmp` is
never built (and since it never lives, it cannot be destructed).

-- Matthieu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120903/681b7400/attachment.html>


More information about the cfe-dev mailing list