c-typeck.c (build_c_cast): Try using a shared constant...

2005-11-07  Paolo Bonzini  <bonzini@gnu.org>

        * c-typeck.c (build_c_cast): Try using a shared constant, and see
        if TREE_OVERFLOW or TREE_CONSTANT_OVERFLOW really changed.

testsuite:
2005-11-07  Paolo Bonzini  <bonzini@gnu.org>

        * gcc.dg/overflow-2.c: New testcase.

From-SVN: r106587
This commit is contained in:
Paolo Bonzini 2005-11-07 10:34:13 +00:00 committed by Paolo Bonzini
parent ab900bfa4d
commit d8e1f97b7e
4 changed files with 31 additions and 6 deletions

View File

@ -1,3 +1,8 @@
2005-11-07 Paolo Bonzini <bonzini@gnu.org>
* c-typeck.c (build_c_cast): Try using a shared constant, and see
if TREE_OVERFLOW or TREE_CONSTANT_OVERFLOW really changed.
2005-11-07 Jakub Jelinek <jakub@redhat.com>
PR rtl-optimization/23567

View File

@ -3500,16 +3500,19 @@ build_c_cast (tree type, tree expr)
/* Ignore any integer overflow caused by the cast. */
if (TREE_CODE (value) == INTEGER_CST)
{
/* If OVALUE had overflow set, then so will VALUE, so it
is safe to overwrite. */
if (CONSTANT_CLASS_P (ovalue))
if (CONSTANT_CLASS_P (ovalue)
&& (TREE_OVERFLOW (ovalue) || TREE_CONSTANT_OVERFLOW (ovalue)))
{
/* Avoid clobbering a shared constant. */
value = copy_node (value);
TREE_OVERFLOW (value) = TREE_OVERFLOW (ovalue);
/* Similarly, constant_overflow cannot have become cleared. */
TREE_CONSTANT_OVERFLOW (value) = TREE_CONSTANT_OVERFLOW (ovalue);
}
else
TREE_OVERFLOW (value) = 0;
else if (TREE_OVERFLOW (value) || TREE_CONSTANT_OVERFLOW (value))
/* Reset VALUE's overflow flags, ensuring constant sharing. */
value = build_int_cst_wide (TREE_TYPE (value),
TREE_INT_CST_LOW (value),
TREE_INT_CST_HIGH (value));
}
}

View File

@ -1,3 +1,7 @@
2005-11-07 Paolo Bonzini <bonzini@gnu.org>
* gcc.dg/overflow-2.c: New testcase.
2005-11-07 Jakub Jelinek <jakub@redhat.com>
PR rtl-optimization/23567

View File

@ -0,0 +1,13 @@
/* { dg-do compile } */
/* { dg-options "-std=c99 -pedantic-errors" } */
/* PR c/24599 */
int
main (void)
{
if ((_Bool)(__INT_MAX__ + 1)) /* { dg-warning "overflow in expression" } */
return 1;
else
return 0;
}