x86 JIT improperly reorders load of field of generic type with assignment to default(T) - by Ben Voigt

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.


7
0
Sign in
to vote
ID 679116 Comments
Status Closed Workarounds
Type Bug Repros 2
Opened 7/11/2011 4:35:45 PM
Access Restriction Public
Moderator Decision Sent to Engineering Team for consideration

Description

In generic code, the initobj opcode is used to set a field of generic type to default(T).

When T is a reference type, this sets the field to null.  However, the JIT optimizer improperly reorders a load of that field before the store, causing the prior value of the field to be used instead of generating a NullReferenceException.
Sign in to post a comment.
Posted by Microsoft on 4/29/2014 at 12:23 PM
Thank you for reporting this issue. This issue has been fixed in Visual Studio 2013. You can install a trial version of Visual Studio 2013 with the fix from: http://go.microsoft.com/?linkid=9832436
Posted by Microsoft on 9/8/2011 at 11:40 AM
Ben, again thank you for taking the time to narrow down this issue and report it. I have fixed it for a future release of the .NET Framework.

Grant Richins
CLR Codegen Developer
Posted by Microsoft on 7/13/2011 at 5:55 PM
Thank you for reporting this issue. Indeed it is a bug in the 32-bit JIT's optimizer. Until we can ship a fix, as a work-around you can annotate the affected method with MethodImplOptions.NoOptimization (http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.methodimploptions.aspx). Also you could experiment with re-arranging your code. Specifically, having an assignment of a reference type (not involving default(T)) after the call to Release should prevent the bug.

Grant Richins
CLR Codegen Developer
Posted by MS-Moderator08 [Feedback Moderator] on 7/11/2011 at 11:25 PM
Thank you for submitting feedback on Visual Studio 2010 and .NET Framework. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by MS-Moderator01 on 7/11/2011 at 5:49 PM
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)