OSDN Git Service

2005-11-07 Paolo Bonzini <bonzini@gnu.org>
authorbonzini <bonzini@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 7 Nov 2005 10:34:13 +0000 (10:34 +0000)
committerbonzini <bonzini@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 7 Nov 2005 10:34:13 +0000 (10:34 +0000)
        * 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@106587 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/overflow-2.c [new file with mode: 0644]

index fb37811..17d02b2 100644 (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
index d322615..80259cc 100644 (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));
        }
     }
 
index 0ab2539..befbe80 100644 (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
diff --git a/gcc/testsuite/gcc.dg/overflow-2.c b/gcc/testsuite/gcc.dg/overflow-2.c
new file mode 100644 (file)
index 0000000..23c22a6
--- /dev/null
@@ -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;
+}