Skip to content

Commit

Permalink
fix issue 15876 - various cases of SEGFAULT when formatting parser er…
Browse files Browse the repository at this point in the history
…rors
  • Loading branch information
Lars-Kristiansen committed Nov 24, 2018
1 parent 1e902fc commit 866c0a3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 10 deletions.
24 changes: 14 additions & 10 deletions src/dmd/hdrgen.d
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public:

override void visit(ExpStatement s)
{
if (s.exp && s.exp.op == TOK.declaration)
if (s.exp && s.exp.op == TOK.declaration &&
(cast(DeclarationExp)s.exp).declaration)
{
// bypass visit(DeclarationExp)
(cast(DeclarationExp)s.exp).declaration.accept(this);
Expand Down Expand Up @@ -636,7 +637,8 @@ public:
{
buf.writestring(Token.toString(s.tok));
buf.writeByte(' ');
s.statement.accept(this);
if (s.statement)
s.statement.accept(this);
}

override void visit(ThrowStatement s)
Expand Down Expand Up @@ -1847,7 +1849,7 @@ public:
buf.writeByte(' ');
typeToBuffer(d.type, d.ident);
}
else
else if (d.ident)
{
declstring = (d.ident == Id.string || d.ident == Id.wstring || d.ident == Id.dstring);
buf.writestring(d.ident.toString());
Expand Down Expand Up @@ -2730,19 +2732,21 @@ public:
* are handled in visit(ExpStatement), so here would be used only when
* we'll directly call Expression.toChars() for debugging.
*/
if (auto v = e.declaration.isVarDeclaration())
if (e.declaration)
{
if (auto v = e.declaration.isVarDeclaration())
{
// For debugging use:
// - Avoid printing newline.
// - Intentionally use the format (Type var;)
// which isn't correct as regular D code.
buf.writeByte('(');
visitVarDecl(v, false);
buf.writeByte(';');
buf.writeByte(')');
buf.writeByte('(');
visitVarDecl(v, false);
buf.writeByte(';');
buf.writeByte(')');
}
else e.declaration.accept(this);
}
else
e.declaration.accept(this);
}

override void visit(TypeidExp e)
Expand Down
1 change: 1 addition & 0 deletions test/fail_compilation/e15876_1.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
o[{scope(x
1 change: 1 addition & 0 deletions test/fail_compilation/e15876_2.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
o[{template
1 change: 1 addition & 0 deletions test/fail_compilation/e15876_3.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
d(={for
1 change: 1 addition & 0 deletions test/fail_compilation/e15876_4.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
typeof){for
1 change: 1 addition & 0 deletions test/fail_compilation/e15876_5.d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
p[{alias

0 comments on commit 866c0a3

Please sign in to comment.