OSDN Git Service

* c-typeck.c (c_start_case): Don't strip conversions from the
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 23 Dec 2001 23:49:32 +0000 (23:49 +0000)
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Sun, 23 Dec 2001 23:49:32 +0000 (23:49 +0000)
controlling expression.  Partially fixes PR c/2454.

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

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@48292 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/execute/20011223-1.c [new file with mode: 0644]

index d2d73ea..1b84b71 100644 (file)
@@ -1,5 +1,10 @@
 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>
+
        * Makefile.in (USER_H): Remove proto.h.
        * config.gcc (c*-convex-*): Set extra_headers=proto.h.
 
index 50d7f9b..eacf4f5 100644 (file)
@@ -7125,7 +7125,6 @@ c_start_case (exp)
        }
       else
        {
-         tree index;
          type = TYPE_MAIN_VARIANT (TREE_TYPE (exp));
 
          if (warn_traditional && !in_system_header
@@ -7135,14 +7134,6 @@ c_start_case (exp)
 
          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;
        }
     }
 
index fadeb19..68f0c61 100644 (file)
@@ -1,3 +1,7 @@
+2001-12-23  Joseph S. Myers  <jsm28@cam.ac.uk>
+
+       * gcc.c-torture/execute/20011223-1.c: New test.
+
 2001-12-21  Richard Henderson  <rth@redhat.com>
 
        * gcc.dg/wtr-aggr-init-1.c: Test that __extension__ disables then
diff --git a/gcc/testsuite/gcc.c-torture/execute/20011223-1.c b/gcc/testsuite/gcc.c-torture/execute/20011223-1.c
new file mode 100644 (file)
index 0000000..18fb720
--- /dev/null
@@ -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);
+  }
+}