Don't multiply fixed buffer size (it's done by runtime). Fixes #654058
authorMarek Safar <marek.safar@gmail.com>
Mon, 22 Nov 2010 17:37:12 +0000 (17:37 +0000)
committerMarek Safar <marek.safar@gmail.com>
Mon, 22 Nov 2010 17:37:12 +0000 (17:37 +0000)
mcs/mcs/field.cs
mcs/tests/gtest-fixedbuffer-09.cs [new file with mode: 0644]

index 661a2a2f0ced29a661810431687f89efb7005811..8933e1a2d87bcbf0b8f86dbda7cb0c1d156279e8 100644 (file)
@@ -357,7 +357,7 @@ namespace Mono.CSharp
                #region Properties
 
                //
-               // Explicit struct layout set be parent
+               // Explicit struct layout set by parent
                //
                public CharSet? CharSet {
                        get; set;
@@ -440,7 +440,6 @@ namespace Mono.CSharp
                                return;
                        }
 
-                       buffer_size *= type_size;
                        EmitFieldSize (buffer_size);
 
                        Compiler.PredefinedAttributes.UnsafeValueType.EmitAttribute (fixed_buffer_type);
diff --git a/mcs/tests/gtest-fixedbuffer-09.cs b/mcs/tests/gtest-fixedbuffer-09.cs
new file mode 100644 (file)
index 0000000..d100cea
--- /dev/null
@@ -0,0 +1,23 @@
+// Compiler options: -unsafe
+
+using System;
+using System.Runtime.CompilerServices;
+
+unsafe struct Foo
+{
+       public fixed long FieldName[32];
+}
+
+class Test
+{
+       public static int Main ()
+       {
+               var t = typeof (Foo);
+               var f = t.GetField ("FieldName");
+               var fbas = f.GetCustomAttributes (typeof (FixedBufferAttribute), true)[0] as FixedBufferAttribute;
+               if (fbas.Length != 32)
+                       return 1;
+
+               return 0;
+       }
+}