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

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

Open
AdamMil opened this Issue Jan 28, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@AdamMil
Copy link

AdamMil commented Jan 28, 2019

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment