PR c/6677 and al.

Eric Botcazou ebotcazou@libertysurf.fr
Thu May 30 05:04:00 GMT 2002


> And indeed, it would appear that your other problem
>
> >  j = ((char) (i * 2)) / 2;
>
> is the same root problem.  We can't look through the narrowing cast as
> readily as we're doing.

Here's the revised version of the patch. It now prevents the distribution
of the truncation down through the left shift when the target type is
signed.

Both parts of the patch are necessary in order to fix the PR, given that
the first case is now redirected to the second one.

Bootstrapped/regtested (C/C++) on i586-pc-linux-gnu (gcc-3_1-branch).


2002-05-30  Eric Botcazou  <ebotcazou@multimania.com>

 PR c/6677
 convert.c (convert_to_integer) [LSHIFT_EXPR]: Don't pass
 the truncation down if the target type is signed.
 fold-const.c (extract_muldiv) [NOP_EXPR]: Don't truncate
 if the target type is a smaller signed type.


/* PR c/6677 */
/* Verify that GCC doesn't bypass a truncation to a
   signed type when folding.  */

extern void abort (void);
extern void exit (int);

int main (void)
{
  int i = 127;
  char j;

  j = ((char) (i << 1)) / 2;

  if (j != -1)
    abort();

  j = ((char) (i * 2)) / 2;

  if (j != -1)
    abort();

  exit(0);
}

--
Eric Botcazou
ebotcazou@multimania.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr6677.diff
Type: application/octet-stream
Size: 2148 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20020530/38306054/attachment.obj>


More information about the Gcc-patches mailing list