Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix basicBlockContinuation after else #1190

Merged
merged 3 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Neo.Compiler.CSharp/Optimizer/Analysers/BasicBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Neo.SmartContract.Manifest;
using Neo.VM;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace Neo.Optimizer
Expand All @@ -24,6 +25,7 @@ namespace Neo.Optimizer
/// The end of a basic block can be a jumping instruction, an ENDFINALLY, a RET, etc.
/// Instructions in the same basic block can be replaced with more effcient ones.
/// </summary>
[DebuggerDisplay("BasicBlock addr={startAddr}")]
public class BasicBlock
{
public readonly int startAddr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,10 @@ public BranchType CoverInstruction(int addr, Stack<TryStack>? stack = null,
// Here we have the exception not catched
if (!coveredMap.TryGetValue(addr, out BranchType value))
throw new BadScriptException($"wrong address {addr}");
Instruction instruction = script.GetInstruction(addr);
if (jumpTargetToSources.ContainsKey(instruction) && addr != entranceAddr)
// on target of jump, start a new recursion to split basic blocks
return coveredMap[firstNotNopAddr] = CoverInstruction(addr, stack, continueFromBasicBlockEntranceAddr: firstNotNopAddr);
if (value != BranchType.UNCOVERED)
{
if (stackType != TryStackType.FINALLY)
Expand All @@ -243,10 +247,6 @@ public BranchType CoverInstruction(int addr, Stack<TryStack>? stack = null,
// FINALLY is OK, but throwed in previous TRY (without catch) or CATCH
return BranchType.THROW; // Do not set coveredMap[entranceAddr] = BranchType.THROW;
}
Instruction instruction = script.GetInstruction(addr);
if (jumpTargetToSources.ContainsKey(instruction) && addr != entranceAddr)
// on target of jump, start a new recursion to split basic blocks
return coveredMap[firstNotNopAddr] = CoverInstruction(addr, stack, continueFromBasicBlockEntranceAddr: addr);
if (instruction.OpCode != OpCode.NOP)
{
coveredMap[addr] = BranchType.OK;
Expand Down
Loading