In mcs:
authorRaja R Harinath <harinath@hurrynot.org>
Fri, 13 May 2005 12:44:43 +0000 (12:44 -0000)
committerRaja R Harinath <harinath@hurrynot.org>
Fri, 13 May 2005 12:44:43 +0000 (12:44 -0000)
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.

svn path=/trunk/mcs/; revision=44495

mcs/mcs/ChangeLog
mcs/mcs/convert.cs
mcs/mcs/expression.cs
mcs/tests/ChangeLog
mcs/tests/Makefile
mcs/tests/test-380.cs [new file with mode: 0644]

index 8d7a50b55ae2cd8c0289127436ab21c8dcde434b..3bccd0fdaac761d67f8668ed5f8f48ec7580bf3c 100644 (file)
@@ -1,3 +1,14 @@
+2005-05-13  Raja R Harinath  <rharinath@novell.com>
+
+       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  <marek.safar@seznam.cz>
        
        * cs-parser.jay: Set readonly context based on special constructs.
index 532fbd4587154cc0e992bf1ad651622b18ce226c..c2b3eddd8610d79ff9487d491b1868c1b7816a14 100644 (file)
@@ -97,7 +97,7 @@ namespace Mono.CSharp {
                        // 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 @@ namespace Mono.CSharp {
                                
                                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);
index 36fda7774d12e0beba2af1cd3f95b32a378e3a5b..ac5efa88632f9501e96d29ad928be5ef85b156f5 100644 (file)
@@ -2274,7 +2274,7 @@ namespace Mono.CSharp {
                                        
                                        return this;
                                }
-                               
+
                                // IntPtr equality
                                if (l == TypeManager.intptr_type && r == TypeManager.intptr_type) {
                                        Type = TypeManager.bool_type;
@@ -2384,6 +2384,25 @@ namespace Mono.CSharp {
                                        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 @@ namespace Mono.CSharp {
                        // 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;
index 009f82c9811064cce16095ad90e63803a6aa7058..777e5d9988d014d86afa01baba8584ac0c2c9dcc 100644 (file)
@@ -1,3 +1,7 @@
+2005-05-13  Raja R Harinath  <rharinath@novell.com>
+
+       * test-380.cs: New test from #74934.
+
 2005-05-12  Raja R Harinath  <harinath@gmail.com>
 
        * test-378.cs: New test from #74920.
index 5e842009787b31cdd7baf4d57eb8ed179db038bc..adb88361ca8cdec51dd926dd7d4b8d9504116d42 100644 (file)
@@ -34,7 +34,7 @@ USE_MCS_FLAGS :=
 # 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
diff --git a/mcs/tests/test-380.cs b/mcs/tests/test-380.cs
new file mode 100644 (file)
index 0000000..1122b48
--- /dev/null
@@ -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;
+        }
+}