Skip to content

Commit

Permalink
Add weka option -template-codegen-depth=<uint> to prevent crashes on …
Browse files Browse the repository at this point in the history
…stack exhaustion upon deep recursion
  • Loading branch information
JohanEngelen committed Mar 9, 2019
1 parent e42597e commit 1865f29
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
10 changes: 10 additions & 0 deletions dmd/dtemplate.d
Original file line number Diff line number Diff line change
Expand Up @@ -6217,6 +6217,16 @@ extern (C++) class TemplateInstance : ScopeDsymbol
*/
final bool needsCodegen()
{
version (IN_WEKA)
{
static uint callDepth;
callDepth++;
scope(exit) callDepth--;

if (global.params.templateCodegenDepth && (callDepth > global.params.templateCodegenDepth))
return false;
}

// Now -allInst is just for the backward compatibility.
if (global.params.allInst)
{
Expand Down
1 change: 1 addition & 0 deletions dmd/globals.d
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ struct Param
version (IN_WEKA)
{
bool enableWekaMods; // Enable specific Weka mods like the template instantiation mods
uint templateCodegenDepth; // Don't codegen templates beyond this recusion depth.
}
}
}
Expand Down
1 change: 1 addition & 0 deletions dmd/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ struct Param

#if IN_WEKA
bool enableWekaMods; // Enable specific Weka mods like the template instantiation mods
uint32_t templateCodegenDepth;
#endif
#endif
};
Expand Down
4 changes: 4 additions & 0 deletions driver/cl_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ static cl::opt<bool, true, FlagParser<bool>> wekaMods(
cl::desc(
"(*) Enable specific Weka mods like the template instantiation mods"),
cl::location(global.params.enableWekaMods), cl::init(true));
static cl::opt<uint32_t, true>
templateCodegenDepth("template-codegen-depth",
cl::desc("Don't codegen templates beyond this recusion depth (0 = off)."),
cl::location(global.params.templateCodegenDepth), cl::init(0));
#endif

cl::opt<LTOKind> ltoMode(
Expand Down

0 comments on commit 1865f29

Please sign in to comment.