This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PR c/6677 and al.
- From: "Eric Botcazou" <ebotcazou at libertysurf dot fr>
- To: "Richard Henderson" <rth at redhat dot com>
- Cc: <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 4 Jun 2002 20:42:33 +0200
- Subject: Re: PR c/6677 and al.
- References: <00fa01c206a2$9759ab60$1f0e81d4@zephyr> <20020528174803.D3599@redhat.com> <004d01c207ae$45550960$bc0124d5@zephyr> <20020602123640.D12875@redhat.com>
[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