Home Dashboard Directory Help
Search

Variable is not incrementing in C# Release x64 by Damien HOFFSCHIR


Status: 

Closed
 as Fixed Help for as Fixed


5
0
Sign in
to vote
Type: Bug
ID: 636466
Opened: 1/17/2011 8:42:09 AM
Access Restriction: Public
0
Workaround(s)
view
3
User(s) can reproduce this bug

Description

Hi,

Could someone explain to me why this piece of code (cf Step tor Reproduce) is doing well when I execute it on a x86 platform and why it fail on x64 ?

If I change something, like removing one of the unused variables, or if I remove the useless for-loop after p_lFirstId++, the strange behavior disappear.

I found that changing "pdb-only" to "full" in my release configuration, it's work again.

If you run the code directly from visual studio, it's doing well too.

Is this a JIT Compiler bug ?

Thank you in advance.
Details
Sign in to post a comment.
Posted by Microsoft on 4/12/2011 at 9:44 AM
Thank you for reporting this issue. It is a bug in the x64 JIT and how it assigns registers to locals and parameters. This has been fixed in a future version of the CLR.

There are several possible work-arounds. One is to remove the useless foreach. Another would be to move the post-increment statement to be after the foreach. Yet another potential work-around would be to apply [System.Runtime.CompilerServices.MethodImplAttribute(MethodImplOptions.NoOptimization)] to the offending method. See http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.methodimploptions.aspx for more information about that flag.

Grant Richins
CLR JIT Developer
Posted by Damien HOFFSCHIR on 3/28/2011 at 2:18 AM
Hi,

Any news about this issues ?

Thank you.
Posted by IDWMaster on 1/18/2011 at 5:30 PM
I had first discovered this issue at http://stackoverflow.com/questions/4715278/variable-is-not-incrementing-in-c-release-x64/4719061#4719061 using the following code:
class Program
{
    static void Main(string[] args)
    {
        Test(null, null, null, 0, 1);            
    }

    public static void Test(
        List<string> liste, List<string> unused1,
        string unused2, int unused3, long p_lFirstId)
    {
        liste = new List<string>();

        StringBuilder sbSql = new StringBuilder();

        for (int i = 0 ; i < 10 ; i++)
        {
            sbSql.Append(p_lFirstId);
            p_lFirstId++;                

            foreach (string sColonne in liste)
            {

            }

        }

        System.Console.WriteLine(sbSql.ToString());
    }
}

The bug only happens in the x64 Release configuration.
Posted by Microsoft on 1/17/2011 at 7:00 PM
Thanks for your feedback.

We are rerouting this issue to the appropriate group within the Visual Studio Product Team for triage and resolution. These specialized experts will follow-up with your issue.
Posted by Microsoft on 1/17/2011 at 9:14 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.