[Mono-bugs] [Bug 35465][Wis] New - [return:] attribute target not properly handled

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
11 Dec 2002 19:09:02 -0000

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 jonpryor@vt.edu.


--- shadow/35465	Wed Dec 11 14:09:02 2002
+++ shadow/35465.tmp.19479	Wed Dec 11 14:09:02 2002
@@ -0,0 +1,103 @@
+Bug#: 35465
+Product: Mono/MCS
+Version: unspecified
+OS: other
+OS Details: 
+Status: NEW   
+Priority: Wishlist
+Component: Misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: jonpryor@vt.edu               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+Summary: [return:] attribute target not properly handled
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+This appears to be an issue with both mono and mcs.  I'm not sure that I
+should enter it twice, so this will be the sole report.
+"return" attribute targets do not behave the same under Mono and .NET. 
+Consider the following program:
+        // file: rat.cs (return attribute target)
+        using System;
+        using System.Reflection;
+        public class MethodAttribute : Attribute {}
+        public class ReturnAttribute : Attribute {}
+        public class Test {
+          [Method]
+          [return: Return]
+          public void Method () {}
+          public static void Main () {
+            Type t = typeof(Test);
+            MethodInfo mi = t.GetMethod("Method");
+            ICustomAttributeProvider cap = mi.ReturnTypeCustomAttributes;
+            if (cap != null) {
+              object[] ca = cap.GetCustomAttributes (true);
+              foreach (object o in ca)
+                Console.WriteLine ("[return: " + o + "]");
+            }
+            else {
+              Console.WriteLine ("Error: no return type custom attributes");
+            }
+          }
+        }
+It compiles properly under both mcs and csc.exe.
+The runtime behavior is incorrect for the mcs-generated program.
+Under mcs/mono:
+        jon@melchior:tmp$ mono rat.exe
+        Error: no return type custom attributes
+Under csc.exe/.NET:
+        K:\tmp>rat.exe
+        [return: ReturnAttribute]
+Note that csc.exe/.NET correctly sees the "return" attribute-targeted
+attribute specified on Test.Method.
+However, it looks to be a Mono library/runtime issue as well.  Under
+csc.exe/mono (compiled with csc.exe, run on Mono):
+        Error: no return type custom attributes
+So the mono runtime doesn't understand "return" attribute targets.
+The last combination, mcs-comiled and run on .NET, produces no output.  I'm
+not sure why this is the case.  (Under Windows XP with Visual Studio .NET
+installed, if that's important.)
+The next step is to examine the IL produced by csc.exe and mcs using
+ildasm.exe.  There are two major difference I saw (just eyeballing the
+code; a diff between the IL produced with `ildasm.exe /all /utf8
+/out=<filename> assembly.exe' was too much to go over).
+First of all, the custom attributes on Test.Method are separated by a
+.param [0] line under csc.exe, but not mcs, e.g.:
+        .method public hidebysig instance void Method() cil managed
+        {
+          .custom instance void MethodAttribute::.ctor() = (01 00 00 00)
+          // the following line was produced by csc.exe but not mcs
+          .param [0] /*08000001*/
+          .custom instance void ReturnAttribute::.ctor() = (01 00 00 00)
+        }
+The other difference (not sure that it matters) was the token numbers
+produced between mcs and csc.exe.  Under mcs, the MethodAttribute got a
+token of 0C000001 while csc.exe gave it 0C000003, and the ReturnAttribute
+got 0C000002 under mcs while csc.exe gave it 0C000001.
+Thus, it appears that both mono and mcs need improvement in handling
+[return:] attribute targets.