Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge upstream stable (dlang/dmd@5f214609d9) #3770

Merged
merged 1 commit into from
Jun 22, 2021
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
17 changes: 17 additions & 0 deletions dmd/dcast.d
Original file line number Diff line number Diff line change
Expand Up @@ -2565,6 +2565,23 @@ Expression castTo(Expression e, Scope* sc, Type t, Type att = null)
}
}

// Casting to noreturn isn't an actual cast
// Rewrite cast(<qual> noreturn) <exp>
// as <exp>, assert(false)
if (t.isTypeNoreturn())
{
// Don't generate an unreachable assert(false) if e will abort
if (e.type.isTypeNoreturn())
{
// Paint e to accomodate for different type qualifiers
e.type = t;
return e;
}

auto ini = t.defaultInitLiteral(e.loc);
return Expression.combine(e, ini);
}

scope CastTo v = new CastTo(sc, t);
e.accept(v);
return v.result;
Expand Down
9 changes: 9 additions & 0 deletions dmd/dinterpret.d
Original file line number Diff line number Diff line change
Expand Up @@ -2214,6 +2214,15 @@ public:
result = getVarExp(e.loc, istate, e.var, goal);
if (exceptionOrCant(result))
return;

// Visit the default initializer for noreturn variables
// (Custom initializers would abort the current function call and exit above)
if (result.type.ty == Tnoreturn)
{
result.accept(this);
return;
}

if ((e.var.storage_class & (STC.ref_ | STC.out_)) == 0 && e.type.baseElemOf().ty != Tstruct)
{
/* Ultimately, STC.ref_|STC.out_ check should be enough to see the
Expand Down
2 changes: 1 addition & 1 deletion dmd/parse.d
Original file line number Diff line number Diff line change
Expand Up @@ -6230,7 +6230,7 @@ LagainStc:
// not merged into the current case. This can happen for
// case 1: ... break;
// debug { case 2: ... }
if (cur.isBreakStatement())
if (cur && cur.isBreakStatement())
break;
}
s = new AST.CompoundStatement(loc, statements);
Expand Down
14 changes: 14 additions & 0 deletions dmd/typesem.d
Original file line number Diff line number Diff line change
Expand Up @@ -4540,6 +4540,19 @@ Expression defaultInit(Type mt, const ref Loc loc)
return new TupleExp(loc, exps);
}

Expression visitNoreturn(TypeNoreturn mt)
{
static if (LOGDEFAULTINIT)
{
printf("TypeNoreturn::defaultInit() '%s'\n", mt.toChars());
}
auto cond = IntegerExp.createBool(false);
auto msg = new StringExp(loc, "Accessed expression of type `noreturn`");
auto ae = new AssertExp(loc, cond, msg);
ae.type = mt;
return ae;
}

switch (mt.ty)
{
case Tvector: return visitVector (cast(TypeVector)mt);
Expand All @@ -4559,6 +4572,7 @@ Expression defaultInit(Type mt, const ref Loc loc)
case Treference:
case Tdelegate:
case Tclass: return new NullExp(loc, mt);
case Tnoreturn: return visitNoreturn(cast(TypeNoreturn) mt);

default: return mt.isTypeBasic() ?
visitBasic(cast(TypeBasic)mt) :
Expand Down
2 changes: 1 addition & 1 deletion runtime/phobos
Submodule phobos updated 0 files