public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: "Joseph S. Myers" <jsm28@cam.ac.uk>
To: jsm28@gcc.gnu.org
Cc: gcc-prs@gcc.gnu.org
Subject: Re: c/2454
Date: Wed, 06 Jun 2001 13:36:00 -0000	[thread overview]
Message-ID: <20010606203600.18066.qmail@sourceware.cygnus.com> (raw)

The following reply was made to PR c/2454; it has been noted by GNATS.

From: "Joseph S. Myers" <jsm28@cam.ac.uk>
To: Neil Booth <neil@daikokuya.demon.co.uk>
Cc: <gcc-gnats@gcc.gnu.org>,  <gcc-patches@gcc.gnu.org>
Subject: Re: c/2454
Date: Wed, 6 Jun 2001 21:32:12 +0100 (BST)

 On 6 Jun 2001, Neil Booth wrote:
 
 >  jsm28@gcc.gnu.org wrote:-
 >  
 >  >      Confirmed as a bug, and a regression from 2.95.  A small
 >  >      testcase is
 >  >      
 >  >      static int i;
 >  >      
 >  >      int
 >  >      main (void)
 >  >      {
 >  >        i = -1;
 >  >        switch((signed char) i) {
 >  >        case 255:
 >  >          abort ();
 >  >        default:
 >  >          exit (0);
 >  >        }
 >  >      }
 >  
 >  Ugh.  These signedness-of-less-than-int issues seem to be endless.
 
 This bug is more complicated than I'd hoped.  I think the patch below 
 addresses a C front end bug that is part of the problem - we shouldn't 
 strip type conversions from the switch case expression.  (2.95 did strip 
 them, but then gave a warning that the case value was out of range.  3.0 
 converts the case value, as required by the C standard - but the 
 conversion should be to the promoted type, int, not signed char.)  
 However, after this patch the testcase still fails with -O2, -Os, -O3.  
 Could someone familiar with the optimizers take a look at this?  This is a 
 regression, but not currently marked as "high".
 
 2001-06-06  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-06-06  Joseph S. Myers  <jsm28@cam.ac.uk>
 
 	* gcc.c-torture/execute/20010606-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/20010606-1.c	Mon Mar 26 23:57:02 2001
 +++ testsuite/gcc.c-torture/execute/20010606-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
 


             reply	other threads:[~2001-06-06 13:36 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-06-06 13:36 Joseph S. Myers [this message]
  -- strict thread matches above, loose matches on Subject: below --
2003-04-28 10:16 c/2454 jakub
2003-01-25 16:06 c/2454 ebotcazou
2002-07-10 18:26 c/2454 sayle
2001-12-23 15:56 c/2454 jsm28
2001-06-06 13:26 c/2454 Neil Booth
2001-06-06 10:06 c/2454 jsm28
2001-06-05 14:36 c/2454 jsm28

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20010606203600.18066.qmail@sourceware.cygnus.com \
    --to=jsm28@cam.ac.uk \
    --cc=gcc-prs@gcc.gnu.org \
    --cc=jsm28@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).