Unplanned
Last Updated: 22 Apr 2020 12:13 by ADMIN
Thomas
Created on: 18 Apr 2020 18:34
Type: Bug Report
0
Wrong code generate for break- statement in nested for loops

 

In certain situations with a for-loop nested inside another loop, a break-statement in the inner loop will decompile to a goto that also exits the outer loop.

If this code is compiled in RELEASE mode:

        public void NestedForTest(IEnumerable<char> line)
        {
            foreach (var ch in line)
            {
                for (int i = 0; i < 4; i++)
                {
                    Console.Write("-");     // If this line is removed it works
                    if (ch == 't') break;
                    Console.Write(ch);
                }
            }
            Console.WriteLine();
        }

 

The following code is decompiled:

        public void NestedForTest(IEnumerable<char> line)
        {
        Label0:
            foreach (char ch in line)
            {
                for (int i = 0; i < 4; i++)
                {
                    Console.Write("-");
                    if (ch == 't')
                    {
      goto Label0;   // THIS IS WRONG!
                    }
                    Console.Write(ch);
                }
            }
            Console.WriteLine();
        }

NOTE:

- It is only a problem when the code is compiled in a RELEASE configuration (in DEBUG it interpret it as a while-loop and the code is correct)

- If the line before the exit-check is removed (see comment in code) it decompiles correctly.

 

                 
Attached Files:
1 comment
ADMIN
Nick Iliev
Posted on: 22 Apr 2020 12:13

Hi Thomas,

 

Thank you for contacting us and for providing detailed information. I can confirm that the issue is reproducible (while using the provided test project) - logging this one as a bug. Any information related to the topic is to be posted here.

 

Regards,
Nick Iliev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.