Bug 22272 - Ccrewrite crashes on Contract.Result<string>
Summary: Ccrewrite crashes on Contract.Result<string>
Status: NEW
Alias: None
Product: Tools
Classification: Mono
Component: other ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-08-21 17:31 UTC by Willem Van Onsem
Modified: 2015-05-02 19:29 UTC (History)
4 users (show)

Tags: ccrewrite error Contracts Spec# specifications
Is this bug a regression?: ---
Last known good build:


Attachments
source code (373 bytes, text/x-csharp)
2014-08-21 17:31 UTC, Willem Van Onsem
Details
stracktrace of the length error (2.25 KB, text/plain)
2014-08-21 17:32 UTC, Willem Van Onsem
Details
error when performing a null check (7.50 KB, text/plain)
2014-08-21 17:32 UTC, Willem Van Onsem
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 22272 on GitHub or Developer Community if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: GitHub Markdown or Developer Community HTML
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
NEW

Description Willem Van Onsem 2014-08-21 17:31:43 UTC
Created attachment 7761 [details]
source code

If one uses contracts to ensure some property on the resulting string type, problems occur when using ccrewrite.

If one uses:

    Contract.Ensures (Contract.Result<string> ().Length > 0x00);

System.NotSupportedException: Unknown instruction in contract: IL_0022: callvirt System.Int32 System.String::get_Length()
  at Mono.CodeContracts.Rewrite.Decompile.Go (Boolean failQuietly) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.PerformRewrite.TransformContracts (Mono.Cecil.ModuleDefinition module, Mono.Cecil.MethodDefinition method, Mono.CodeContracts.Rewrite.ContractsRuntime contractsRuntime) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.PerformRewrite.RewriteMethod (Mono.Cecil.ModuleDefinition module, Mono.Cecil.MethodDefinition method, Mono.CodeContracts.Rewrite.ContractsRuntime contractsRuntime) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.PerformRewrite.Rewrite (Mono.Cecil.AssemblyDefinition assembly) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.Rewriter.RewriteImpl () [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.Rewriter.Rewrite (Mono.CodeContracts.Rewrite.RewriterOptions options) [0x00000] in <filename unknown>:0 
  at ccrewrite.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.NotSupportedException: Unknown instruction in contract: IL_0022: callvirt System.Int32 System.String::get_Length()
  at Mono.CodeContracts.Rewrite.Decompile.Go (Boolean failQuietly) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.PerformRewrite.TransformContracts (Mono.Cecil.ModuleDefinition module, Mono.Cecil.MethodDefinition method, Mono.CodeContracts.Rewrite.ContractsRuntime contractsRuntime) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.PerformRewrite.RewriteMethod (Mono.Cecil.ModuleDefinition module, Mono.Cecil.MethodDefinition method, Mono.CodeContracts.Rewrite.ContractsRuntime contractsRuntime) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.PerformRewrite.Rewrite (Mono.Cecil.AssemblyDefinition assembly) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.Rewriter.RewriteImpl () [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.Rewriter.Rewrite (Mono.CodeContracts.Rewrite.RewriterOptions options) [0x00000] in <filename unknown>:0 
  at ccrewrite.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 

An even more unexpected error occurs when performing a null check:

    Contract.Ensures (Contract.Result<string> () != null);

    Unhandled Exception:
System.NotSupportedException: Cannot handle Contract.Result()
  at Mono.CodeContracts.Rewrite.TransformContractsVisitor.VisitCall (Mono.CodeContracts.Rewrite.Ast.ExprCall e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.Visit (Mono.CodeContracts.Rewrite.Ast.Expr e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitCollection (IEnumerable`1 collection, Mono.CodeContracts.Rewrite.Ast.Expr e, System.Func`2 fnCreateNew) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitCollection (Mono.CodeContracts.Rewrite.Ast.Expr e, System.Func`2 fnCreateNew, Mono.CodeContracts.Rewrite.Ast.Expr[] collection) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitCompareEqual (Mono.CodeContracts.Rewrite.Ast.ExprCompareEqual e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.Visit (Mono.CodeContracts.Rewrite.Ast.Expr e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitCollection (IEnumerable`1 collection, Mono.CodeContracts.Rewrite.Ast.Expr e, System.Func`2 fnCreateNew) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitCollection (Mono.CodeContracts.Rewrite.Ast.Expr e, System.Func`2 fnCreateNew, Mono.CodeContracts.Rewrite.Ast.Expr[] collection) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitCompareEqual (Mono.CodeContracts.Rewrite.Ast.ExprCompareEqual e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.Visit (Mono.CodeContracts.Rewrite.Ast.Expr e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitCollection (IEnumerable`1 collection, Mono.CodeContracts.Rewrite.Ast.Expr e, System.Func`2 fnCreateNew) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitCall (Mono.CodeContracts.Rewrite.Ast.ExprCall e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.TransformContractsVisitor.VisitCall (Mono.CodeContracts.Rewrite.Ast.ExprCall e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.Visit (Mono.CodeContracts.Rewrite.Ast.Expr e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitCollection (IEnumerable`1 collection, Mono.CodeContracts.Rewrite.Ast.Expr e, System.Func`2 fnCreateNew) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitBlock (Mono.CodeContracts.Rewrite.Ast.ExprBlock e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.Visit (Mono.CodeContracts.Rewrite.Ast.Expr e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.PerformRewrite.TransformContracts (Mono.Cecil.ModuleDefinition module, Mono.Cecil.MethodDefinition method, Mono.CodeContracts.Rewrite.ContractsRuntime contractsRuntime) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.PerformRewrite.RewriteMethod (Mono.Cecil.ModuleDefinition module, Mono.Cecil.MethodDefinition method, Mono.CodeContracts.Rewrite.ContractsRuntime contractsRuntime) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.PerformRewrite.Rewrite (Mono.Cecil.AssemblyDefinition assembly) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.Rewriter.RewriteImpl () [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.Rewriter.Rewrite (Mono.CodeContracts.Rewrite.RewriterOptions options) [0x00000] in <filename unknown>:0 
  at ccrewrite.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.NotSupportedException: Cannot handle Contract.Result()
  at Mono.CodeContracts.Rewrite.TransformContractsVisitor.VisitCall (Mono.CodeContracts.Rewrite.Ast.ExprCall e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.Visit (Mono.CodeContracts.Rewrite.Ast.Expr e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitCollection (IEnumerable`1 collection, Mono.CodeContracts.Rewrite.Ast.Expr e, System.Func`2 fnCreateNew) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitCollection (Mono.CodeContracts.Rewrite.Ast.Expr e, System.Func`2 fnCreateNew, Mono.CodeContracts.Rewrite.Ast.Expr[] collection) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitCompareEqual (Mono.CodeContracts.Rewrite.Ast.ExprCompareEqual e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.Visit (Mono.CodeContracts.Rewrite.Ast.Expr e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitCollection (IEnumerable`1 collection, Mono.CodeContracts.Rewrite.Ast.Expr e, System.Func`2 fnCreateNew) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitCollection (Mono.CodeContracts.Rewrite.Ast.Expr e, System.Func`2 fnCreateNew, Mono.CodeContracts.Rewrite.Ast.Expr[] collection) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitCompareEqual (Mono.CodeContracts.Rewrite.Ast.ExprCompareEqual e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.Visit (Mono.CodeContracts.Rewrite.Ast.Expr e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitCollection (IEnumerable`1 collection, Mono.CodeContracts.Rewrite.Ast.Expr e, System.Func`2 fnCreateNew) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitCall (Mono.CodeContracts.Rewrite.Ast.ExprCall e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.TransformContractsVisitor.VisitCall (Mono.CodeContracts.Rewrite.Ast.ExprCall e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.Visit (Mono.CodeContracts.Rewrite.Ast.Expr e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitCollection (IEnumerable`1 collection, Mono.CodeContracts.Rewrite.Ast.Expr e, System.Func`2 fnCreateNew) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.VisitBlock (Mono.CodeContracts.Rewrite.Ast.ExprBlock e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.AstVisitors.ExprVisitor.Visit (Mono.CodeContracts.Rewrite.Ast.Expr e) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.PerformRewrite.TransformContracts (Mono.Cecil.ModuleDefinition module, Mono.Cecil.MethodDefinition method, Mono.CodeContracts.Rewrite.ContractsRuntime contractsRuntime) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.PerformRewrite.RewriteMethod (Mono.Cecil.ModuleDefinition module, Mono.Cecil.MethodDefinition method, Mono.CodeContracts.Rewrite.ContractsRuntime contractsRuntime) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.PerformRewrite.Rewrite (Mono.Cecil.AssemblyDefinition assembly) [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.Rewriter.RewriteImpl () [0x00000] in <filename unknown>:0 
  at Mono.CodeContracts.Rewrite.Rewriter.Rewrite (Mono.CodeContracts.Rewrite.RewriterOptions options) [0x00000] in <filename unknown>:0 
  at ccrewrite.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0

(One would at least expect that performing a null check is more trivial than performing a length check, but the stacktrace of ccrewrite seems to indicate that the problem occurs with the result.
Comment 1 Willem Van Onsem 2014-08-21 17:32:16 UTC
Created attachment 7762 [details]
stracktrace of the length error
Comment 2 Willem Van Onsem 2014-08-21 17:32:42 UTC
Created attachment 7763 [details]
error when performing a null check
Comment 3 Willem Van Onsem 2014-08-21 17:36:16 UTC
versions: mono JIT compiler 3.2.8 x86
Defined symbols DEBUG;CONTRACTS_FULL