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]

Partial patch for c/2454 applied


This patch, previously sent six months ago, partially addresses PR
c/2454 (a regression of sorts from 2.95 to 3.x).  I didn't previously
commit it since the test case still fails at some optimization levels
and I wanted someone familiar with the optimizers to look at this; but
no-one did.  Since I think this is a clearly correct bug fix, albeit
not fully fixing the test case because of some bug elsewhere, I've now
updated the test case filename, retested that it bootstraps with no
regressions on i686-pc-linux-gnu and applied it to the mainline.

2001-12-23  Joseph S. Myers  <jsm28@cam.ac.uk>

	* c-typeck.c (c_start_case): Don't strip conversions from the
	controlling expression.  Partially fixes PR c/2454.

2001-12-23  Joseph S. Myers  <jsm28@cam.ac.uk>

	* gcc.c-torture/execute/20011223-1.c: New test.

--- c-typeck.c.orig	Tue Jun  5 07:05:47 2001
+++ c-typeck.c	Wed Jun  6 16:54:11 2001
@@ -7044,7 +7044,6 @@
 	}
       else
 	{
-	  tree index;
 	  type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
 
 	  if (warn_traditional && !in_system_header
@@ -7054,14 +7053,6 @@
 
 	  exp = default_conversion (exp);
 	  type = TREE_TYPE (exp);
-	  index = get_unwidened (exp, NULL_TREE);
-	  /* We can't strip a conversion from a signed type to an
-	     unsigned, because if we did, int_fits_type_p would do the
-	     wrong thing when checking case values for being in range,
-	     and it's too hard to do the right thing.  */
-	  if (TREE_UNSIGNED (TREE_TYPE (exp))
-	      == TREE_UNSIGNED (TREE_TYPE (index)))
-	    exp = index;
 	}
     }
 
--- testsuite/gcc.c-torture/execute/20011223-1.c	Mon Mar 26 23:57:02 2001
+++ testsuite/gcc.c-torture/execute/20011223-1.c	Wed Jun  6 16:53:01 2001
@@ -0,0 +1,22 @@
+/* Origin: Joseph Myers <jsm28@cam.ac.uk>.  */
+/* Case labels in a switch statement are converted to the promoted
+   type of the controlling expression, not an unpromoted version.
+   Reported as PR c/2454 by
+   Andreas Krakowczyk <Andreas.Krakowczyk@fujitsu-siemens.com>.  */
+
+extern void exit (int);
+extern void abort (void);
+
+static int i;
+
+int
+main (void)
+{
+  i = -1;
+  switch ((signed char) i) {
+  case 255:
+    abort ();
+  default:
+    exit (0);
+  }
+}

-- 
Joseph S. Myers
jsm28@cam.ac.uk


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