This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] PR 5675


Here is a partial patch for PR 5675.  This restores the behaviour of
gcc mainline back to gcc 3.4, so it makes the PR no longer a 4.0
regression.

The problem was introduced by this patch:

    2003-02-16  Jan Hubicka  <jh@suse.cz>

	* c-typeck.c (build_c_cast):  Fold constant variables into
	initial values.

    http://gcc.gnu.org/ml/gcc-patches/2003-02/msg01334.html

I think this patch is conceptually wrong, as was discussed in the
e-mail thread.  We should not be doing this type of optimization in
the frontend.

Fortunately, this patch is no longer necessary.  It was intended to
fix a test case which appears here:
    http://gcc.gnu.org/ml/gcc-patches/2003-02/msg01325.html
This test case now works as expected even if the patch to
build_c_cast() is reverted.  The same optimization is now applied by
the tree-ssa-ccp pass.

I've verified that reverting the patch causes on testsuite changes on
i686-pc-linux-gnu.  I'm currently running a bootstrap on
i686-pc-linux-gnu.  OK to commit if the bootstrap completes?


gcc/ChangeLog:

2005-01-13  Ian Lance Taylor  <ian@airs.com>

	PR c/5675
	* c-typeck.c (build_c_cast): Revert patch of 2003-02-16: don't
	fold constant variables into initial values.

gcc/testsuite/ChangeLog:

2005-01-13  Ian Lance Taylor  <ian@airs.com>

	PR c/5675
	* gcc.dg/c90-const-expr-3.c: Remove xfails on tests which now
	pass--those that refer just to the variable, possibly with a
	cast.
	* gcc.dg/c99-const-expr-3.c: Likewise.


Index: c-typeck.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-typeck.c,v
retrieving revision 1.407
diff -p -u -r1.407 c-typeck.c
--- c-typeck.c	5 Jan 2005 15:22:38 -0000	1.407
+++ c-typeck.c	13 Jan 2005 15:03:49 -0000
@@ -3202,9 +3202,6 @@ build_c_cast (tree type, tree expr)
 	pedwarn ("ISO C forbids conversion of object pointer to function pointer type");
 
       ovalue = value;
-      /* Replace a nonvolatile const static variable with its value.  */
-      if (optimize && TREE_CODE (value) == VAR_DECL)
-	value = decl_constant_value (value);
       value = convert (type, value);
 
       /* Ignore any integer overflow caused by the cast.  */
Index: testsuite/gcc.dg/c90-const-expr-3.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/c90-const-expr-3.c,v
retrieving revision 1.5
diff -p -u -r1.5 c90-const-expr-3.c
--- testsuite/gcc.dg/c90-const-expr-3.c	25 Oct 2004 00:17:07 -0000	1.5
+++ testsuite/gcc.dg/c90-const-expr-3.c	13 Jan 2005 15:03:49 -0000
@@ -26,7 +26,7 @@ void
 foo (void)
 {
   ASSERT_NPC (0);
-  ASSERT_NOT_NPC (ZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
+  ASSERT_NOT_NPC (ZERO);
   ASSERT_NPC (0 + 0);
   ASSERT_NOT_NPC (ZERO + 0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
   ASSERT_NOT_NPC (ZERO + ZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
@@ -35,11 +35,11 @@ foo (void)
   ASSERT_NPC (-0);
   ASSERT_NOT_NPC (-ZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
   ASSERT_NPC ((char) 0);
-  ASSERT_NOT_NPC ((char) ZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
+  ASSERT_NOT_NPC ((char) ZERO);
   ASSERT_NPC ((int) 0);
-  ASSERT_NOT_NPC ((int) ZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
+  ASSERT_NOT_NPC ((int) ZERO);
   ASSERT_NPC ((int) 0.0);
-  ASSERT_NOT_NPC ((int) DZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
+  ASSERT_NOT_NPC ((int) DZERO);
   ASSERT_NOT_NPC ((int) +0.0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
   ASSERT_NOT_NPC ((int) (0.0+0.0)); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
   ASSERT_NOT_NPC ((int) (double)0.0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
Index: testsuite/gcc.dg/c99-const-expr-3.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/testsuite/gcc.dg/c99-const-expr-3.c,v
retrieving revision 1.4
diff -p -u -r1.4 c99-const-expr-3.c
--- testsuite/gcc.dg/c99-const-expr-3.c	24 Oct 2004 20:59:29 -0000	1.4
+++ testsuite/gcc.dg/c99-const-expr-3.c	13 Jan 2005 15:03:49 -0000
@@ -25,7 +25,7 @@ void
 foo (void)
 {
   ASSERT_NPC (0);
-  ASSERT_NOT_NPC (ZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
+  ASSERT_NOT_NPC (ZERO);
   ASSERT_NPC (0 + 0);
   ASSERT_NOT_NPC (ZERO + 0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
   ASSERT_NOT_NPC (ZERO + ZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
@@ -34,11 +34,11 @@ foo (void)
   ASSERT_NPC (-0);
   ASSERT_NOT_NPC (-ZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
   ASSERT_NPC ((char) 0);
-  ASSERT_NOT_NPC ((char) ZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
+  ASSERT_NOT_NPC ((char) ZERO);
   ASSERT_NPC ((int) 0);
-  ASSERT_NOT_NPC ((int) ZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
+  ASSERT_NOT_NPC ((int) ZERO);
   ASSERT_NPC ((int) 0.0);
-  ASSERT_NOT_NPC ((int) DZERO); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
+  ASSERT_NOT_NPC ((int) DZERO);
   ASSERT_NOT_NPC ((int) +0.0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
   ASSERT_NOT_NPC ((int) (0.0+0.0)); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */
   ASSERT_NOT_NPC ((int) (double)0.0); /* { dg-bogus "incompatible" "bogus null pointer constant" { xfail *-*-* } } */


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]