From 6eb5351149fbe37f06c43bacb968e71bd73dfbb5 Mon Sep 17 00:00:00 2001 From: Joseph Myers Date: Sun, 23 Dec 2001 23:49:32 +0000 Subject: [PATCH] re PR c/2454 (Test Program A0376972.c fails with gcc-20010320, works with gcc-2.95.3) * c-typeck.c (c_start_case): Don't strip conversions from the controlling expression. Partially fixes PR c/2454. testsuite: * gcc.c-torture/execute/20011223-1.c: New test. From-SVN: r48292 --- gcc/ChangeLog | 5 +++++ gcc/c-typeck.c | 9 -------- gcc/testsuite/ChangeLog | 4 ++++ .../gcc.c-torture/execute/20011223-1.c | 22 +++++++++++++++++++ 4 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/execute/20011223-1.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d2d73ea437f..1b84b719068 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2001-12-23 Joseph S. Myers + + * 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 * Makefile.in (USER_H): Remove proto.h. diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index 50d7f9bf5d2..eacf4f56691 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -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; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fadeb19fe39..68f0c616887 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2001-12-23 Joseph S. Myers + + * gcc.c-torture/execute/20011223-1.c: New test. + 2001-12-21 Richard Henderson * 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 index 00000000000..18fb7208927 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/20011223-1.c @@ -0,0 +1,22 @@ +/* Origin: Joseph Myers . */ +/* 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 . */ + +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); + } +} -- 2.30.2