Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Codegen not generating proper cleanup code for exception handling in destructor of temporary objects. #13550

Open Quuxplusone opened 12 years ago

Quuxplusone commented 12 years ago
Bugzilla Link PR13505
Status NEW
Importance P normal
Reported by rahul (rahulsingh.mnnit@gmail.com)
Reported on 2012-08-01 11:05:33 -0700
Last modified on 2013-10-18 17:42:45 -0700
Version 3.1
Hardware PC All
CC isanbard@gmail.com, llvm-bugs@lists.llvm.org, llvm.org@halfy.net, rahul.s1@samsung.com, rjmccall@apple.com
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
extern "C" void abort ();

int thrown;

int as;
struct a {
  a () { ++as; }
  ~a () { --as; if (thrown++ == 0) throw 42; }
};

int f (a const&) { return 1; }
int f (a const&, a const&) { return 1; }

int bs;
int as_sav;
struct b {
  b (...) { ++bs; }
  ~b ()   { --bs; as_sav = as; }
};

bool p;
void g()
{
  if (p) throw 42;
}

int main () {
  thrown = 0;
  try {
    b tmp(f (a(), a()));

    g();
  }
  catch (...) {}

  // We throw when the first a is destroyed, which should destroy b before
  // the other a.
  if (as_sav != 1)
    abort ();

}

For the above code , when observing the .bc file , it is clear that when the
statement  b tmp(f (a(), a())); is getting executed --> at the end of statement
, Clang is destroying the temporaries a(),a() created but since the destructor
of a()  is throwing an exception , Clang should have called b's destructor too
in the cleanup part but in the bytecode , the cleanup part for b is missing so
for the above test case , in case of exception occuring in the destructors of
the temporaries , b's constructor is not getting called.
Quuxplusone commented 12 years ago

I concur; this is a known problem which will be somewhat awkward to fix.

Quuxplusone commented 11 years ago

Is it projected that this would take a long time to fix? Is it a release blocker?

Quuxplusone commented 11 years ago

It's subtle and would take some serious work to fix. It's not a blocker.