[Mono-bugs] [Bug 76599][Nor] New - C# 2.0 fixed size buffers treated as memory-position-fixed

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Sun Oct 30 11:55:52 EST 2005


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 jan.oravec at 6com.sk.

http://bugzilla.ximian.com/show_bug.cgi?id=76599

--- shadow/76599	2005-10-30 11:55:52.000000000 -0500
+++ shadow/76599.tmp.10189	2005-10-30 11:55:52.000000000 -0500
@@ -0,0 +1,92 @@
+Bug#: 76599
+Product: Mono: Compilers
+Version: 1.1
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: C#
+AssignedTo: rharinath at novell.com                            
+ReportedBy: jan.oravec at 6com.sk               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: C# 2.0 fixed size buffers treated as memory-position-fixed
+
+Description of Problem:
+
+The current SVN MONO treats fixed size buffers as if their memory position
+was fixed which is incorrect. If we compile the following code in MONO:
+
+public unsafe struct B
+{
+  private fixed int a[5];
+
+  public void Foo()
+  {
+    int* x = &a[0]; /* No fixed statement required -> BUG */
+    
+    /* Some code that can trigger GC collection */
+    System.GC.Collect ();
+
+    System.Console.WriteLine("pointer: "+(ulong)x);
+    System.Console.WriteLine("pointer: "+(ulong)&a[0]);
+  }
+}
+
+Compiler does not require usage of 'fixed' statement when creating pointer
+from fixed size buffer 'a' which is a bug, because the structure may be
+contained in class which is subject to relocation by GC. When the resulting
+code is run on MSFT .NET framework, we can easily get the above code write
+pointers to different memory locations.
+
+Furthermore, if we try to compile the following code:
+
+public unsafe class C
+{
+  private B x;
+
+  public void Goo()
+  {
+    x.Foo();
+            
+    fixed(B* y=&x)
+    {
+    }
+  }  
+}
+
+The compiler throws an exception:
+
+Exception caught by the compiler while compiling:
+   Block that caused the problem begin at: a.cs(20,15):
+System.InvalidCastException: Cannot cast from source type to destination type.
+
+Unhandled Exception: System.InvalidCastException: Cannot cast from source
+type to destination type.
+in <0x001e5> Mono.CSharp.TypeManager:IsUnmanagedType (System.Type t)
+in <0x00016> Mono.CSharp.TypeManager:VerifyUnManaged (System.Type t,
+Location loc)
+in <0x00144> Mono.CSharp.ComposedCast:DoResolveAsTypeStep
+(Mono.CSharp.EmitContext ec)
+in <0x0002d> Mono.CSharp.TypeExpr:ResolveAsTypeStep
+(Mono.CSharp.EmitContext ec, Boolean silent)
+in <0x0004e> Mono.CSharp.Expression:ResolveAsTypeTerminal
+(Mono.CSharp.EmitContext ec, Boolean silent)
+in <0x0003c> Mono.CSharp.LocalInfo:Resolve (Mono.CSharp.EmitContext ec)
+in <0x00194> Mono.CSharp.Block:ResolveMeta (Mono.CSharp.ToplevelBlock
+toplevel, Mono.CSharp.EmitContext ec, Mono.CSharp.InternalParameters ip)
+in <0x00967> Mono.CSharp.Block:ResolveMeta (Mono.CSharp.ToplevelBlock
+toplevel, Mono.CSharp.EmitContext ec, Mono.CSharp.InternalParameters ip)
+in <0x00056> Mono.CSharp.ToplevelBlock:ResolveMeta (Mono.CSharp.EmitContext
+ec, Mono.CSharp.InternalParameters ip)
+in <0x0010a> Mono.CSharp.EmitContext:ResolveTopBlock
+(Mono.CSharp.EmitContext anonymous_method_host, Mono.CSharp.ToplevelBlock
+block, Mono.CSharp.InternalParameters ip, IMethodData md, System.Boolean
+unreachable)
+
+If we comment out the fixed() statement, no exception is thrown and the
+code compiles.


More information about the mono-bugs mailing list