summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2018-01-14 21:55:52 +0800
committerJohn Hodge <tpg@ucc.asn.au>2018-01-14 21:55:52 +0800
commitc3ce26d8190ca93f6ed763610e849eff9c95e8d5 (patch)
tree135e1005ced2c2bc2b467b6e8a4fbd85c9f55d83 /src
parentda001a95415d4b79b66b8b223db5ece4059cf0e5 (diff)
downloadmrust-c3ce26d8190ca93f6ed763610e849eff9c95e8d5.tar.gz
MIR Optimise - Prevent infinite recrusion in inlining
Diffstat (limited to 'src')
-rw-r--r--src/mir/optimise.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/mir/optimise.cpp b/src/mir/optimise.cpp
index 552bc157..06064bfe 100644
--- a/src/mir/optimise.cpp
+++ b/src/mir/optimise.cpp
@@ -808,6 +808,16 @@ bool MIR_Optimise_Inlining(::MIR::TypeResolve& state, ::MIR::Function& fcn, bool
if( fcn.blocks.size() != fcn.blocks[0].terminator.as_Switch().targets.size()+3 )
return false;
// TODO: Check for the parameter being a Constant?
+ for(size_t i = 1; i < fcn.blocks.size(); i ++)
+ {
+ if( fcn.blocks[i].terminator.is_Call() )
+ {
+ const auto& te = fcn.blocks[i].terminator.as_Call();
+ // Recursion, don't inline.
+ if( te.fcn.is_Path() && te.fcn.as_Path() == path )
+ return false;
+ }
+ }
return true;
}
else
@@ -1177,6 +1187,11 @@ bool MIR_Optimise_Inlining(::MIR::TypeResolve& state, ::MIR::Function& fcn, bool
const auto* called_mir = get_called_mir(state, path, cloner.params);
if( !called_mir )
continue ;
+ if( called_mir == &fcn )
+ {
+ DEBUG("Can't inline - recursion");
+ continue ;
+ }
// Check the size of the target function.
// Inline IF: