Home Dashboard Directory Help
Search

Jitter or C# compiler bug by CodesInChaos


Status: 

Closed
 as Duplicate Help for as Duplicate


2
1
Sign in
to vote
Type: Bug
ID: 671105
Opened: 5/27/2011 4:15:37 AM
Access Restriction: Public
Moderator Decision: Sent to Engineering Team for consideration
0
Workaround(s)
view
1
User(s) can reproduce this bug

Description

The code:

static readonly long variableZero=0;
public static void Broken2( long ticks2) //ticks2==634363497820000000
{
     long ticks = ticks2+variableZero;
     if (ticks != (ticks - (ticks % 10000L)))
     {
     ...

enters the if clause even for values of ticks2 for which it shouldn't. If variableZero is replaced by a compile-time constant the code works.

This happens only in the release build and only when running without a debugger.

This report is based on the following stackoverflow thread:
http://stackoverflow.com/questions/6054987/if-statement-appears-to-be-evaluating-even-when-condition-evaluates-to-false/

Code to reproduce:
http://nopaste.info/2c99a0e028_nl.html
Details
Sign in to post a comment.
Posted by Microsoft on 8/3/2011 at 11:40 AM
Thanks a lot for reporting this issue!

We have fixed this issue and you will be able to see the fix in the next release of .Net Frameworks.

Thanks
Lakshan Fernando
CLR Jit Test Lead
Posted by Porges on 6/29/2011 at 3:59 PM
Any updates on this?
Posted by MS-Moderator09 [Feedback Moderator] on 6/1/2011 at 1:46 AM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for review. We will contact you if we require any additional information.
Posted by Porges on 5/30/2011 at 3:10 PM
> The strange behavior only occurs if no debugger is attached. i.e. when Jit optimization is enabled. So I'm pretty sure it's a jitter bug.

You can attach a debugger if you disable "disable JIT optimizations". :)
Posted by CodesInChaos on 5/30/2011 at 1:51 PM
I've added a C# console project exhibiting the behavior.

The strange behavior only occurs if no debugger is attached. i.e. when Jit optimization is enabled. So I'm pretty sure it's a jitter bug.
Posted by MS-Moderator09 on 5/30/2011 at 3:26 AM
Thank you for reporting this issue. Unfortunately, we are unable to reproduce the issue with the steps you provided.

Could you please provide us with a sample project zip?

It would be greatly appreciated if you could provide us this information as quickly as possible.

Thank you
Posted by MS-Moderator01 on 5/27/2011 at 7:50 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.
File Name Submitted By Submitted On File Size  
StrangeIfBehavior.zip 5/30/2011 1 KB