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

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 636466 Comments
Status Closed Workarounds
Type Bug Repros 3
Opened 1/17/2011 8:42:09 AM
Access Restriction Public



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.
Sign in to post a comment.
Posted by Grant [MSFT] 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 for more information about that flag.

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

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 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++)

            foreach (string sColonne in liste)




The bug only happens in the x64 Release configuration.
Posted by Helen [MSFT] 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(