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]

Re: PR c/6677 and al.


> 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

Attachment: pr6677.diff
Description: Binary data


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