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.


[Sorry for the delay]

> Why are you special-casing signed types?  The
> following test case fails as well.

Because:
- this test case is not in the PR ;-)
- I didn't check it,
- I thought it would have succeeded because of

fold-const.c (extract_muldiv) [NOP_EXPR]:

    case CONVERT_EXPR:  case NON_LVALUE_EXPR:  case NOP_EXPR:
      /* If op0 is an expression, and is unsigned, and the type is
  smaller than ctype, then we cannot widen the expression.  */
      if ((TREE_CODE_CLASS (TREE_CODE (op0)) == '<'
    || TREE_CODE_CLASS (TREE_CODE (op0)) == '1'
    || TREE_CODE_CLASS (TREE_CODE (op0)) == '2'
    || TREE_CODE_CLASS (TREE_CODE (op0)) == 'e')
   && TREE_UNSIGNED (TREE_TYPE (op0))
   && ! (TREE_CODE (TREE_TYPE (op0)) == INTEGER_TYPE
  && TYPE_IS_SIZETYPE (TREE_TYPE (op0)))
   && (GET_MODE_SIZE (TYPE_MODE (ctype))
              > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))))
 break;

- convert.c (convert_to_integer) [LSHIFT_EXPR]: Don't pass
  the truncation down if the target type is signed.

I still think this transformation is valid for unsigned types.


Anyway, I think we have first to agree on what should go in the testcase.

/* PR c/6677 */
/* Verify that GCC doesn't perform illegal simplifications
   when folding constants.  */

#include <limits.h>

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

int main (void)
{
  int i;
  signed char j;
  unsigned char k;
  unsigned int u;

  i = SCHAR_MAX;

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

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

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

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

  i = UCHAR_MAX;

  k = ((unsigned char) (i << 1)) / 2;

  if (k != UCHAR_MAX/2)
    abort();

  k = ((unsigned char) (i * 2)) / 2;

  if (k != UCHAR_MAX/2)
    abort();

  exit(0);
}

All tests fail on the 3_1 branch (all succeed if i is an unsigned int). Do you see
anything else ?

--
Eric Botcazou
ebotcazou@multimania.com


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