[Mono-bugs] [Bug 52730][Wis] New - We generate invalid IL for the access of static readonly fields in ctors
bugzilla-daemon@bugzilla.ximian.com
bugzilla-daemon@bugzilla.ximian.com
Fri, 9 Jan 2004 22:46:33 -0500 (EST)
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by bmaurer@users.sf.net.
http://bugzilla.ximian.com/show_bug.cgi?id=52730
--- shadow/52730 2004-01-09 22:46:33.000000000 -0500
+++ shadow/52730.tmp.21662 2004-01-09 22:46:33.000000000 -0500
@@ -0,0 +1,51 @@
+Bug#: 52730
+Product: Mono/Compilers
+Version: unspecified
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Wishlist
+Component: C#
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: bmaurer@users.sf.net
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: We generate invalid IL for the access of static readonly fields in ctors
+
+In this code:
+using System;
+
+class T {
+ static readonly DateTime Foo = new DateTime (1900, 1, 1);
+
+ public T ()
+ {
+ Console.WriteLine (".ctor (): " + Foo.Ticks);
+ }
+
+ static void Main ()
+ {
+ Console.WriteLine ("Main (): " + Foo.Ticks);
+ T t = new T ();
+ }
+}
+
+For the .ctor we generate:
+
+IL_000b: ldsflda valuetype [mscorlib]'System.DateTime' 'T'::'Foo'
+IL_0010: call instance int64 valuetype [mscorlib]'System.DateTime'::'ge
+t_Ticks'()
+
+While for the static method we generate:
+IL_0005: ldsfld valuetype [mscorlib]'System.DateTime' 'T'::'Foo'
+IL_000a: stloc.1
+IL_000b: ldloca.s 1
+IL_000d: call instance int64 valuetype [mscorlib]'System.DateTime'::'ge
+t_Ticks'()
+
+The code for the ctor is invalid. You cant load the address of a readonly
+field except for in a .cctor. PEVerify complains about this.