Bug 311809 (MONO35465) - [return:] attribute target not properly handled
Summary: [return:] attribute target not properly handled
Status: RESOLVED FIXED
Alias: MONO35465
Product: Mono: Compilers
Classification: Mono
Component: C# (show other bugs)
Version: unspecified
Hardware: Other Other
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Ravi Pratap
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-12-11 21:09 UTC by Jonathan Pryor
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 18:04:35 UTC


---- Reported by jonpryor@vt.edu 2002-12-11 14:09:02 MST ----

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.



---- Additional Comments From ravi@ximian.com 2002-12-11 15:39:21 MST ----

Thank you very much for the detailed bug report - I believe this is
because mcs doesn't special case the return attribute target :-)

I shall take care of this right away - I remember there is a special
method to set the return custom attribute. Hmmm ...



---- Additional Comments From ravi@ximian.com 2002-12-18 19:41:57 MST ----

The mcs part of the bug has been fixed in CVS. SRE has no support for
ReturnTypeCustomAttributes yet so that bug should be separately filed.
Could you please take care of that Jon ? 

I am closing this bug.


Unknown operating system other. Setting to default OS "Other".