re PR middle-end/37103 (possible integer codegen bug)

PR middle-end/37103
	* fold-const.c (fold_widened_comparison): Do not allow
	sign changes that change the result even if shorter type
	is wider than arg1_unw's type.

	* gcc.c-torture/execute/20080813-1.c: New test.

From-SVN: r139093
This commit is contained in:
Jakub Jelinek 2008-08-14 11:02:46 +02:00 committed by Jakub Jelinek
parent cf04a1931a
commit 2e1d24744b
4 changed files with 43 additions and 3 deletions

View file

@ -1,3 +1,10 @@
2008-08-14 Jakub Jelinek <jakub@redhat.com>
PR middle-end/37103
* fold-const.c (fold_widened_comparison): Do not allow
sign changes that change the result even if shorter type
is wider than arg1_unw's type.
2008-08-13 Kazu Hirata <kazu@codesourcery.com>
* gcc.dg/arm-g2.c, gcc.dg/arm-mmx-1.c, gcc.dg/arm-scd42-2.c:

View file

@ -6733,10 +6733,8 @@ fold_widened_comparison (enum tree_code code, tree type, tree arg0, tree arg1)
if ((code == EQ_EXPR || code == NE_EXPR
|| TYPE_UNSIGNED (TREE_TYPE (arg0)) == TYPE_UNSIGNED (shorter_type))
&& (TREE_TYPE (arg1_unw) == shorter_type
|| (TYPE_PRECISION (shorter_type)
> TYPE_PRECISION (TREE_TYPE (arg1_unw)))
|| ((TYPE_PRECISION (shorter_type)
== TYPE_PRECISION (TREE_TYPE (arg1_unw)))
>= TYPE_PRECISION (TREE_TYPE (arg1_unw)))
&& (TYPE_UNSIGNED (shorter_type)
== TYPE_UNSIGNED (TREE_TYPE (arg1_unw))))
|| (TREE_CODE (arg1_unw) == INTEGER_CST

View file

@ -1,3 +1,8 @@
2008-08-14 Jakub Jelinek <jakub@redhat.com>
PR middle-end/37103
* gcc.c-torture/execute/20080813-1.c: New test.
2008-08-13 H.J. Lu <hongjiu.lu@intel.com>
* gcc.target/i386/incoming-1.c: Skip *-*-darwin*.

View file

@ -0,0 +1,30 @@
/* PR middle-end/37103 */
extern void abort (void);
void
foo (unsigned short x)
{
signed char y = -1;
if (x == y)
abort ();
}
void
bar (unsigned short x)
{
unsigned char y = -1;
if (x == y)
abort ();
}
int
main (void)
{
if (sizeof (int) == sizeof (short))
return 0;
foo (-1);
if (sizeof (short) > 1)
bar (-1);
return 0;
}