Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/ddmd/backend/rtlsym.d
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ enum
RTLSYM_MONITOREXIT,
RTLSYM_CRITICALENTER,
RTLSYM_CRITICALEXIT,
RTLSYM_SWITCH_STRING,
RTLSYM_SWITCH_USTRING,
RTLSYM_SWITCH_DSTRING,
RTLSYM_SWITCH_STRING, // unused
RTLSYM_SWITCH_USTRING, // unused
RTLSYM_SWITCH_DSTRING, // unused
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://issues.dlang.org/show_bug.cgi?id=9395 would be very useful here ;-)

RTLSYM_DSWITCHERR,
RTLSYM_DHIDDENFUNC,
RTLSYM_NEWCLASS,
Expand Down Expand Up @@ -104,11 +104,11 @@ enum
RTLSYM_ARRAYCAST,
RTLSYM_ARRAYEQ,
RTLSYM_ARRAYEQ2,
RTLSYM_ARRAYCMP,
RTLSYM_ARRAYCMP2,
RTLSYM_ARRAYCMPCHAR,
RTLSYM_OBJ_EQ,
RTLSYM_OBJ_CMP,
RTLSYM_ARRAYCMP, // unused
RTLSYM_ARRAYCMP2, // unused
RTLSYM_ARRAYCMPCHAR, // unused
RTLSYM_OBJ_EQ, // unused
RTLSYM_OBJ_CMP, // unused

RTLSYM_EXCEPT_HANDLER2,
RTLSYM_EXCEPT_HANDLER3,
Expand Down
1 change: 1 addition & 0 deletions src/ddmd/id.d
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ immutable Msgtable[] msgtable =
{ "__cmp" },
{ "__equals"},
{ "__switch"},
{ "__switch_error"},

// varargs implementation
{ "va_start" },
Expand Down
22 changes: 8 additions & 14 deletions src/ddmd/s2ir.d
Original file line number Diff line number Diff line change
Expand Up @@ -689,21 +689,15 @@ extern (C++) class S2irVisitor : Visitor

override void visit(SwitchErrorStatement s)
{
// SwitchErrors are lowered to a CallExpression to object.__switch_error() in druntime
// We still need the call wrapped in SwitchErrorStatement to pass compiler error checks.
assert(s.exp !is null, "SwitchErrorStatement needs to have a valid Expression.");

Blockx *blx = irs.blx;

//printf("SwitchErrorStatement.toIR()\n");
elem *e;
if (global.params.checkAction == CHECKACTION.C)
{
e = callCAssert(irs, s.loc, null, null, "no switch default");
}
else
{
auto efilename = el_ptr(toSymbol(cast(Dsymbol)blx._module));
auto elinnum = el_long(TYint, s.loc.linnum);
e = el_bin(OPcall, TYvoid, el_var(getRtlsym(RTLSYM_DSWITCHERR)), el_param(elinnum, efilename));
}
block_appendexp(blx.curblock, e);
//printf("SwitchErrorStatement.toIR(), exp = %s\n", s.exp ? s.exp.toChars() : "");
incUsage(irs, s.loc);
block_appendexp(blx.curblock, toElemDtor(s.exp, irs));
}

/**************************************
Expand Down Expand Up @@ -828,7 +822,7 @@ extern (C++) class S2irVisitor : Visitor
//printf("ExpStatement.toIR(), exp = %s\n", s.exp ? s.exp.toChars() : "");
incUsage(irs, s.loc);
if (s.exp)
block_appendexp(blx.curblock,toElemDtor(s.exp, irs));
block_appendexp(blx.curblock, toElemDtor(s.exp, irs));
}

/**************************************
Expand Down
8 changes: 8 additions & 0 deletions src/ddmd/statement.d
Original file line number Diff line number Diff line change
Expand Up @@ -1834,11 +1834,19 @@ extern (C++) final class GotoCaseStatement : Statement
*/
extern (C++) final class SwitchErrorStatement : Statement
{
Expression exp;

extern (D) this(Loc loc)
{
super(loc);
}

final extern (D) this(Loc loc, Expression exp)
{
super(loc);
this.exp = exp;
}

override void accept(Visitor v)
{
v.visit(this);
Expand Down
17 changes: 15 additions & 2 deletions src/ddmd/statementsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -2484,13 +2484,26 @@ else
if (!ss.isFinal && !ss._body.isErrorStatement())
ss.error("switch statement without a default; use `final switch` or add `default: assert(0);` or add `default: break;`");

// Generate runtime error if the default is hit
// Generate runtime error if the default is hit
auto a = new Statements();
CompoundStatement cs;
Statement s;

if (global.params.useSwitchError == CHECKENABLE.on)
s = new SwitchErrorStatement(ss.loc);
{
Expression sl = new IdentifierExp(ss.loc, Id.empty);
sl = new DotIdExp(ss.loc, sl, Id.object);
sl = new DotIdExp(ss.loc, sl, Id.__switch_error);

Expressions* args = new Expressions();
args.push(new StringExp(ss.loc, cast(char*) ss.loc.filename));
args.push(new IntegerExp(ss.loc.linnum));

sl = new CallExp(ss.loc, sl, args);
sl.expressionSemantic(sc);

s = new SwitchErrorStatement(ss.loc, sl);
}
else
s = new ExpStatement(ss.loc, new HaltExp(ss.loc));

Expand Down