From b30063377737ba34e9ace3ce285d3bc2eb14d1a3 Mon Sep 17 00:00:00 2001 From: Eric Botcazou Date: Tue, 23 Dec 2003 06:26:41 +0100 Subject: [PATCH] re PR c/13382 (Type information for const pointer disappears during optimisation.) 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 | 6 ++++++ gcc/c-typeck.c | 6 ++---- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/gcc.dg/null-pointer-1.c | 20 ++++++++++++++++++++ 4 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/null-pointer-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 54d5577a045..81b80dff928 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2003-12-23 Eric Botcazou + + 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 * doc/invoke.texi: Deprecate -fwritable-strings. diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index eee6d551783..682cbc0585f 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -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) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c96f5ec2a2a..bf06beaf5af 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2003-12-23 Eric Botcazou + + * gcc.dg/null-pointer-1.c: New test. + 2003-12-22 Mark Mitchell * 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 index 00000000000..8cc15c6d866 --- /dev/null +++ b/gcc/testsuite/gcc.dg/null-pointer-1.c @@ -0,0 +1,20 @@ +/* PR c/13382 */ +/* Origin: Richard Hutchinson */ + +/* 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; +}