Skip to content

loop flags are not reset in nested loops, causing bad output #24

@AdamMil

Description

@AdamMil

When new state blocks are pushed onto the state stack, the loop state is not reset. This causes failures processing nested loops. Try compiling and decompiling this code:

while(true)
{
	if (true)
	{
		if (true)
		{
				continue;
		}
	}

	for(local i = 0; i <= 10; i++)
	{
		if (true)
		{
				continue;
		}
		else if (true)
		{
			if (true)
			{
			}
			else
			{
			}
		}
	}
}

The output is:

while (true)
{
	if (true)
	{
		if (true)
		{
			continue;
		}
	}

	local i = 0;

	while (i <= 10)
	{
		if (true)
		{
			continue;
		}
		else if (true)
		{
			if (true)
			{
			}
			else
			{
			}
		}

		i++;
	}
}

The 'for' loop has changed into an infinite loop. I think when pushing states onto the state stack, the loop flags should be cleared:

// While block found - push loop block
BlockState prevBlockState = state.m_BlockState;
state.m_BlockState.inLoop = BlockState::WhileLoop;
state.m_BlockState.loopFlags = 0; // CLEAR THE LOOP FLAGS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions