re PR c/13382 (Type information for const pointer disappears during optimisation.)
authorEric Botcazou <ebotcazou@libertysurf.fr>
Tue, 23 Dec 2003 05:26:41 +0000 (06:26 +0100)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Tue, 23 Dec 2003 05:26:41 +0000 (05:26 +0000)
PR c/13382
* c-typeck.c (convert_for_assignment): When converting from
integral type to pointer type, always call convert.

From-SVN: r74960

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/null-pointer-1.c [new file with mode: 0644]

index 54d5577a04514ddcdbfbba5f2d2315bd070588de..81b80dff928b3e3bdf9d7048aabb1cbfd2d8592f 100644 (file)
@@ -1,3 +1,9 @@
+2003-12-23  Eric Botcazou  <ebotcazou@libertysurf.fr>
+
+       PR c/13382
+       * c-typeck.c (convert_for_assignment): When converting from
+       integral type to pointer type, always call convert.
+
 2003-12-22  Mark Mitchell  <mark@codesourcery.com>
 
        * doc/invoke.texi: Deprecate -fwritable-strings.
index eee6d5517835fa33d702c0721696b324acb3aa4b..682cbc0585fdb32c4ea3dbbe3f8f5622833f8355 100644 (file)
@@ -3608,12 +3608,10 @@ convert_for_assignment (tree type, tree rhs, const char *errtype,
             && TREE_CODE (TREE_TYPE (rhs)) == INTEGER_TYPE
             && TREE_CODE (TREE_OPERAND (rhs, 0)) == INTEGER_CST
             && integer_zerop (TREE_OPERAND (rhs, 0))))
-       {
          warn_for_assignment ("%s makes pointer from integer without a cast",
                               errtype, funname, parmnum);
-         return convert (type, rhs);
-       }
-      return null_pointer_node;
+
+      return convert (type, rhs);
     }
   else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
     {
index c96f5ec2a2ab37081ddf8453f410f9119ba355e1..bf06beaf5afa5d8d724fc4342905133c194b706a 100644 (file)
@@ -1,3 +1,7 @@
+2003-12-23  Eric Botcazou  <ebotcazou@libertysurf.fr>
+
+       * gcc.dg/null-pointer-1.c: New test.
+
 2003-12-22  Mark Mitchell  <mark@codesourcery.com>
 
        * g++.old-deja/g++.jason/template18.C: Remove.
diff --git a/gcc/testsuite/gcc.dg/null-pointer-1.c b/gcc/testsuite/gcc.dg/null-pointer-1.c
new file mode 100644 (file)
index 0000000..8cc15c6
--- /dev/null
@@ -0,0 +1,20 @@
+/* PR c/13382 */
+/* Origin: Richard Hutchinson <richard.hutchinson@asa.co.uk> */
+
+/* Verify that the null initializer is converted to the right
+   pointer type.  */
+
+/* { dg-do compile } */
+/* { dg-options "-O" } */
+
+struct t
+{
+  int aMember;
+};
+
+struct t *const aPointer = 0;
+
+void foo()
+{
+  int anInt = (aPointer == 0) ? 0 : aPointer->aMember;
+}