[Mono-bugs] [Bug 56821][Wis] New - Constant folding is not done on true || x

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Sun, 11 Apr 2004 22:46:25 -0400 (EDT)


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 bmaurer@users.sf.net.

http://bugzilla.ximian.com/show_bug.cgi?id=56821

--- shadow/56821	2004-04-11 22:46:25.000000000 -0400
+++ shadow/56821.tmp.8885	2004-04-11 22:46:25.000000000 -0400
@@ -0,0 +1,65 @@
+Bug#: 56821
+Product: Mono: Compilers
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: C#
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: bmaurer@users.sf.net               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Constant folding is not done on true || x
+
+We do not do constant folding on logical operators where one side is
+constant. One way this manifests itself as a bug is the following:
+
+class T {
+	static bool b;
+	const bool FOO = true;
+	static void Main () {
+		int i;
+		if (FOO || b)
+			i = 1;
+		
+		System.Console.WriteLine (i);
+	}
+}
+
+We give a def. assignment error, because we believe that the if statement
+might not be entered. However, csc gives no error. As well, it does not
+emit any conditional code.
+
+The way csc handles this has some very interesting pitfalls. Consider the code:
+
+class T {
+	bool b;
+	const bool FOO = true;
+	static T a;
+	static void Main () {
+		int i;
+		if (a.b || FOO)
+			i = 1;
+		
+		System.Console.WriteLine (i);
+	}
+}
+
+You have to make sure the side effect of loading a.b is done, because in
+this case, the program will throw a null reference exception. However, you
+must still realize that i is assigned.
+
+class T {
+	static bool b;
+	const bool FOO = true | b;
+	static void Main () {
+	}
+}
+
+Does not compile. Sorta weird, because this means there must be 2 constant
+resolution stages.