[Mono-bugs] [Bug 78899][Nor] New - C# compiler should use unsigned arithmetic and should support overflow check on pointers
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Wed Jul 19 08:15:49 EDT 2006
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 kornelpal at gmail.com.
http://bugzilla.ximian.com/show_bug.cgi?id=78899
--- shadow/78899 2006-07-19 08:15:49.000000000 -0400
+++ shadow/78899.tmp.7377 2006-07-19 08:15:49.000000000 -0400
@@ -0,0 +1,84 @@
+Bug#: 78899
+Product: Mono: Compilers
+Version: unspecified
+OS: All
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: C#
+AssignedTo: rharinath at novell.com
+ReportedBy: kornelpal at gmail.com
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: C# compiler should use unsigned arithmetic and should support overflow check on pointers
+
+The CheckPtr method in the attached source code is compiled to the
+following using MS csc.exe that is exactly what I expect:
+
+ IL_0000: ldarg.0
+ IL_0001: ldarg.1
+ IL_0002: add
+ IL_0003: ldarg.0
+ IL_0004: bge.un.s IL_000c
+ IL_0006: newobj instance void [mscorlib]System.Exception::.ctor()
+ IL_000b: throw
+ IL_000c: ldarg.0
+ IL_000d: ldarg.1
+ IL_000e: add
+ IL_000f: ldarg.0
+ IL_0010: bge.un.s IL_0018
+ IL_0012: newobj instance void [mscorlib]System.Exception::.ctor()
+ IL_0017: throw
+ IL_0018: ldarg.0
+ IL_0019: ldarg.1
+ IL_001a: add.ovf.un
+ IL_001b: ldarg.0
+ IL_001c: bge.un.s IL_0024
+ IL_001e: newobj instance void [mscorlib]System.Exception::.ctor()
+ IL_0023: throw
+ IL_0024: ret
+
+mcs on the other hand compiles the same code to the following:
+
+ IL_0000: ldarg.0
+ IL_0001: conv.i
+ IL_0002: ldarg.1
+ IL_0003: add
+ IL_0004: ldarg.0
+ IL_0005: bge IL_0010
+ IL_000a: newobj instance void [mscorlib]System.Exception::.ctor()
+ IL_000f: throw
+ IL_0010: ldarg.0
+ IL_0011: conv.i
+ IL_0012: ldarg.1
+ IL_0013: add
+ IL_0014: ldarg.0
+ IL_0015: clt
+ IL_0017: brfalse IL_0022
+ IL_001c: newobj instance void [mscorlib]System.Exception::.ctor()
+ IL_0021: throw
+ IL_0022: ldarg.0
+ IL_0023: conv.i
+ IL_0024: ldarg.1
+ IL_0025: add
+ IL_0026: ldarg.0
+ IL_0027: clt
+ IL_0029: brfalse IL_0034
+ IL_002e: newobj instance void [mscorlib]System.Exception::.ctor()
+ IL_0033: throw
+ IL_0034: ret
+
+The result is that no exception is thrown.
+
+Some key bugs in the compiled IL code:
+- conv.i is unnecessary
+- bge.un should be used instead of bge
+- add.ovf.un should be used in checked context
+
+Some optimization bugs:
+- bge.un.s could be used instead of bge.un
+- when unchecked or checked is used clt and brfalse is used instead of bge
More information about the mono-bugs
mailing list