Skip to content

Commit

Permalink
fix Issue 10664 - Win64: exception handling does not work with COMDAT…
Browse files Browse the repository at this point in the history
… folding
  • Loading branch information
WalterBright authored and dlang-bot committed Sep 15, 2020
1 parent 18fd0ff commit 5ca705a
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/dmd/s2ir.d
Expand Up @@ -1105,6 +1105,24 @@ private extern (C++) class S2irVisitor : Visitor
bcatch.Bcatchtype = toSymbol(cs.type.toBasetype());
tryblock.appendSucc(bcatch);
block_goto(blx, BCjcatch, null);

if (cs.type && irs.params.isWindows && irs.params.is64bit) // Win64
{
/* The linker will attempt to merge together identical functions,
* even if the catch types differ. So add a reference to the
* catch type here.
* https://issues.dlang.org/show_bug.cgi?id=10664
*/
auto tc = cs.type.toBasetype().isTypeClass();
if (!tc.sym.vclassinfo)
tc.sym.vclassinfo = TypeInfoClassDeclaration.create(tc);
auto sinfo = toSymbol(tc.sym.vclassinfo);
elem* ex = el_var(sinfo);
ex.Ety = mTYvolatile | TYnptr;
ex = el_una(OPind, TYint, ex);
block_appendexp(irs.blx.curblock, ex);
}

if (cs.handler !is null)
{
StmtState catchState = StmtState(stmtstate, s);
Expand Down
41 changes: 41 additions & 0 deletions test/runnable/test4.d
Expand Up @@ -1425,6 +1425,46 @@ void test59()
}


/* ================================ */
// https://issues.dlang.org/show_bug.cgi?id=10664

Exception collectExceptionE(int delegate () expression, ref int result)

This comment has been minimized.

Copy link
@MoonlightSentinel

MoonlightSentinel Sep 15, 2020

Contributor

This doesn't actually test anything because tests are run with -L/OPT:NOICF on windows to work around the "fixed" issue...

{
try
{
result = expression();
}
catch (Exception e)
{
return e;
}
return null;
}

RangeError collectExceptionR(int delegate () expression, ref int result)
{
try
{
result = expression();
}
catch (RangeError e)
{
return e;
}
return null;
}

void test10664()
{
int b;
int foo() { throw new Exception("blah"); }
assert(collectExceptionE(&foo, b));

int[] a = new int[3];
int goo() { return a[4]; }
collectExceptionR(&goo, b);
}

/* ================================ */


Expand Down Expand Up @@ -1487,6 +1527,7 @@ int main()
test57();
test58();
test59();
test10664();

printf("Success\n");
return 0;
Expand Down

0 comments on commit 5ca705a

Please sign in to comment.