diff options
author | John Hodge <tpg@ucc.asn.au> | 2018-01-14 21:55:52 +0800 |
---|---|---|
committer | John Hodge <tpg@ucc.asn.au> | 2018-01-14 21:55:52 +0800 |
commit | c3ce26d8190ca93f6ed763610e849eff9c95e8d5 (patch) | |
tree | 135e1005ced2c2bc2b467b6e8a4fbd85c9f55d83 /src | |
parent | da001a95415d4b79b66b8b223db5ece4059cf0e5 (diff) | |
download | mrust-c3ce26d8190ca93f6ed763610e849eff9c95e8d5.tar.gz |
MIR Optimise - Prevent infinite recrusion in inlining
Diffstat (limited to 'src')
-rw-r--r-- | src/mir/optimise.cpp | 15 |
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: |