Skip to content

Commit

Permalink
fix Issue 14708 - destructor for temporary not called during stack un…
Browse files Browse the repository at this point in the history
…winding
  • Loading branch information
9rnsr committed Sep 1, 2015
1 parent fa02c61 commit e20c63c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/backend/cod2.c
Expand Up @@ -5079,9 +5079,14 @@ code *cddctor(elem *e,regm_t *pretregs)
*/
usednteh |= EHcleanup;
if (config.exe == EX_NT)
{ usednteh |= NTEHcleanup | NTEH_try;
{
usednteh |= NTEHcleanup | NTEH_try;
nteh_usevars();
}
else
{
usednteh |= EHtry;
}
assert(*pretregs == 0);
code cs;
cs.Iop = ESCAPE | ESCdctor;
Expand Down Expand Up @@ -5117,9 +5122,14 @@ code *cdddtor(elem *e,regm_t *pretregs)
*/
usednteh |= EHcleanup;
if (config.exe == EX_NT)
{ usednteh |= NTEHcleanup | NTEH_try;
{
usednteh |= NTEHcleanup | NTEH_try;
nteh_usevars();
}
else
{
usednteh |= EHtry;
}

code cs;
cs.Iop = ESCAPE | ESCddtor;
Expand Down
50 changes: 50 additions & 0 deletions test/runnable/sdtor.d
Expand Up @@ -3942,6 +3942,55 @@ void test14264()
assert(dtor == 4);
}

/**********************************/
// 14708

bool dtor14708 = false;

struct S14708
{
int n;

void* get(void* p = null)
{
return null;
}

~this()
{
//printf("dtor\n");
dtor14708 = true;
}
}

S14708 makeS14708(int n)
{
return S14708(n);
}

void foo14708(void* x)
{
throw new Exception("fail!");
}

void bar14708()
{
foo14708(makeS14708(1).get());
// A temporary is allocated on stack for the
// return value from makeS(1).
// When foo throws exception, it's dtor should be called
// during unwinding stack, but it does not happen in Win64.
}

void test14708()
{
try
{
bar14708();
} catch (Exception e) {}
assert(dtor14708); // fails!
}

/**********************************/
// 14838

Expand Down Expand Up @@ -4111,6 +4160,7 @@ int main()
test13669();
test13095();
test14264();
test14708();
test14838();

printf("Success\n");
Expand Down

0 comments on commit e20c63c

Please sign in to comment.