Skip to content

Commit

Permalink
Add dummy variable to forbid a jump into synchronized block
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Dec 3, 2013
1 parent d4afed7 commit ddb5e65
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/statement.c
Original file line number Diff line number Diff line change
Expand Up @@ -4319,7 +4319,8 @@ Statement *SynchronizedStatement::semantic(Scope *sc)
#endif
}
else
{ /* Generate our own critical section, then rewrite as:
{
/* Generate our own critical section, then rewrite as:
* __gshared byte[CriticalSection.sizeof] critsec;
* _d_criticalenter(critsec.ptr);
* try { body } finally { _d_criticalexit(critsec.ptr); }
Expand All @@ -4332,6 +4333,13 @@ Statement *SynchronizedStatement::semantic(Scope *sc)
Statements *cs = new Statements();
cs->push(new ExpStatement(loc, tmp));

/* This is just a dummy variable for "goto skips declaration" error.
* Backend optimizer could remove this unused variable.
*/
VarDeclaration *v = new VarDeclaration(loc, Type::tvoidptr, Lexer::uniqueId("__sync"), NULL);
v->semantic(sc);
cs->push(new ExpStatement(loc, v));

Parameters* args = new Parameters;
args->push(new Parameter(STCin, t->pointerTo(), NULL, NULL));

Expand Down

0 comments on commit ddb5e65

Please sign in to comment.