Author: raja
Date: 2005-05-13 08:44:43 -0400 (Fri, 13 May 2005)
New Revision: 44495
Added:
trunk/mcs/tests/test-380.cs
Modified:
trunk/mcs/mcs/ChangeLog
trunk/mcs/mcs/convert.cs
trunk/mcs/mcs/expression.cs
trunk/mcs/tests/ChangeLog
trunk/mcs/tests/Makefile
Log:
In mcs:
Fix #74934.
* expression.cs (BinaryResolveOperator): If one of the operands of
an equality comparison is 'null' and the other is a pointer type,
convert the null to a NullPointer.
* convert.cs (ImplicitReferenceConversion): If the expression is a
NullLiteral and the target type is a pointer type, return a
NullPointer instead.
(ImplicitConversionStandard): Likewise.
In tests:
* test-380.cs: New test from #74934.
Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog 2005-05-13 11:57:53 UTC (rev 44494)
+++ trunk/mcs/mcs/ChangeLog 2005-05-13 12:44:43 UTC (rev 44495)
@@ -1,3 +1,14 @@
+2005-05-13 Raja R Harinath <[EMAIL PROTECTED]>
+
+ Fix #74934.
+ * expression.cs (BinaryResolveOperator): If one of the operands of
+ an equality comparison is 'null' and the other is a pointer type,
+ convert the null to a NullPointer.
+ * convert.cs (ImplicitReferenceConversion): If the expression is a
+ NullLiteral and the target type is a pointer type, return a
+ NullPointer instead.
+ (ImplicitConversionStandard): Likewise.
+
2005-05-13 Marek Safar <[EMAIL PROTECTED]>
* cs-parser.jay: Set readonly context based on special constructs.
Modified: trunk/mcs/mcs/convert.cs
===================================================================
--- trunk/mcs/mcs/convert.cs 2005-05-13 11:57:53 UTC (rev 44494)
+++ trunk/mcs/mcs/convert.cs 2005-05-13 12:44:43 UTC (rev 44495)
@@ -97,7 +97,7 @@
// from the null type to any reference-type.
if (expr_type == TypeManager.null_type){
if (target_type.IsPointer)
- return new EmptyCast (expr,
target_type);
+ return new EmptyCast (NullPointer.Null,
target_type);
if (!target_type.IsValueType)
return new NullCast (expr, target_type);
@@ -1156,7 +1156,7 @@
if (target_type.IsPointer) {
if (expr_type == TypeManager.null_type)
- return new EmptyCast (expr,
target_type);
+ return new EmptyCast
(NullPointer.Null, target_type);
if (expr_type ==
TypeManager.void_ptr_type)
return new EmptyCast (expr,
target_type);
Modified: trunk/mcs/mcs/expression.cs
===================================================================
--- trunk/mcs/mcs/expression.cs 2005-05-13 11:57:53 UTC (rev 44494)
+++ trunk/mcs/mcs/expression.cs 2005-05-13 12:44:43 UTC (rev 44495)
@@ -2274,7 +2274,7 @@
return this;
}
-
+
// IntPtr equality
if (l == TypeManager.intptr_type && r ==
TypeManager.intptr_type) {
Type = TypeManager.bool_type;
@@ -2384,6 +2384,25 @@
return this;
}
+ if (l.IsPointer || r.IsPointer) {
+ if (l.IsPointer && r.IsPointer) {
+ type = TypeManager.bool_type;
+ return this;
+ }
+
+ if (l.IsPointer && r ==
TypeManager.null_type) {
+ right = new EmptyCast
(NullPointer.Null, l);
+ type = TypeManager.bool_type;
+ return this;
+ }
+
+ if (r.IsPointer && l ==
TypeManager.null_type) {
+ left = new EmptyCast
(NullPointer.Null, r);
+ type = TypeManager.bool_type;
+ return this;
+ }
+ }
+
//
// operator != (object a, object b)
// operator == (object a, object b)
@@ -2639,8 +2658,7 @@
// Pointer comparison
//
if (l.IsPointer && r.IsPointer){
- if (oper == Operator.Equality || oper ==
Operator.Inequality ||
- oper == Operator.LessThan || oper ==
Operator.LessThanOrEqual ||
+ if (oper == Operator.LessThan || oper ==
Operator.LessThanOrEqual ||
oper == Operator.GreaterThan || oper ==
Operator.GreaterThanOrEqual){
type = TypeManager.bool_type;
return this;
Modified: trunk/mcs/tests/ChangeLog
===================================================================
--- trunk/mcs/tests/ChangeLog 2005-05-13 11:57:53 UTC (rev 44494)
+++ trunk/mcs/tests/ChangeLog 2005-05-13 12:44:43 UTC (rev 44495)
@@ -1,3 +1,7 @@
+2005-05-13 Raja R Harinath <[EMAIL PROTECTED]>
+
+ * test-380.cs: New test from #74934.
+
2005-05-12 Raja R Harinath <[EMAIL PROTECTED]>
* test-378.cs: New test from #74920.
Modified: trunk/mcs/tests/Makefile
===================================================================
--- trunk/mcs/tests/Makefile 2005-05-13 11:57:53 UTC (rev 44494)
+++ trunk/mcs/tests/Makefile 2005-05-13 12:44:43 UTC (rev 44495)
@@ -34,7 +34,7 @@
# He may also move some to TEST_EXCLUDE_net_2_0 if some of the merges are
inappropriate for GMCS.
#
NEW_TEST_SOURCES_common = test-336 test-369 cls-test-6 test-294 \
- test-372 test-375 test-376 test-377 test-378 test-360
+ test-372 test-375 test-376 test-377 test-378 test-360 test-380
#
# Please do _not_ add any tests here - all new tests should go into
NEW_TEST_SOURCES_common
Added: trunk/mcs/tests/test-380.cs
===================================================================
--- trunk/mcs/tests/test-380.cs 2005-05-13 11:57:53 UTC (rev 44494)
+++ trunk/mcs/tests/test-380.cs 2005-05-13 12:44:43 UTC (rev 44495)
@@ -0,0 +1,11 @@
+// Compiler options: -unsafe
+
+class T {
+ static unsafe int Main () {
+ int *a = null;
+ int **b = &a;
+ if (*b == null)
+ return 0;
+ return 1;
+ }
+}
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches