OSDN Git Service

PR c/54103
authorjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 20 Sep 2012 20:49:06 +0000 (20:49 +0000)
committerjsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4>
Thu, 20 Sep 2012 20:49:06 +0000 (20:49 +0000)
* c-typeck.c (build_unary_op): Pass original argument of
TRUTH_NOT_EXPR to c_objc_common_truthvalue_conversion, then remove
any C_MAYBE_CONST_EXPR, if it has integer operands.
(build_binary_op): Pass original arguments of TRUTH_ANDIF_EXPR,
TRUTH_ORIF_EXPR, TRUTH_AND_EXPR, TRUTH_OR_EXPR and TRUTH_XOR_EXPR
to c_objc_common_truthvalue_conversion, then remove any
C_MAYBE_CONST_EXPR, if they have integer operands.  Use
c_objc_common_truthvalue_conversion not
c_common_truthvalue_conversion.
(c_objc_common_truthvalue_conversion): Build NE_EXPR directly and
call note_integer_operands for arguments with integer operands
that are not integer constants.

testsuite:
* gcc.c-torture/compile/pr54103-1.c,
gcc.c-torture/compile/pr54103-2.c,
gcc.c-torture/compile/pr54103-3.c,
gcc.c-torture/compile/pr54103-4.c,
gcc.c-torture/compile/pr54103-5.c,
gcc.c-torture/compile/pr54103-6.c: New tests.
* gcc.dg/c90-const-expr-8.c: Update expected column number.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@191589 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/c-typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr54103-1.c [new file with mode: 0644]
gcc/testsuite/gcc.c-torture/compile/pr54103-2.c [new file with mode: 0644]
gcc/testsuite/gcc.c-torture/compile/pr54103-3.c [new file with mode: 0644]
gcc/testsuite/gcc.c-torture/compile/pr54103-4.c [new file with mode: 0644]
gcc/testsuite/gcc.c-torture/compile/pr54103-5.c [new file with mode: 0644]
gcc/testsuite/gcc.c-torture/compile/pr54103-6.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c90-const-expr-8.c

index 6b8f6d6..583c2eb 100644 (file)
@@ -1,3 +1,19 @@
+2012-09-20  Joseph Myers  <joseph@codesourcery.com>
+
+       PR c/54103
+       * c-typeck.c (build_unary_op): Pass original argument of
+       TRUTH_NOT_EXPR to c_objc_common_truthvalue_conversion, then remove
+       any C_MAYBE_CONST_EXPR, if it has integer operands.
+       (build_binary_op): Pass original arguments of TRUTH_ANDIF_EXPR,
+       TRUTH_ORIF_EXPR, TRUTH_AND_EXPR, TRUTH_OR_EXPR and TRUTH_XOR_EXPR
+       to c_objc_common_truthvalue_conversion, then remove any
+       C_MAYBE_CONST_EXPR, if they have integer operands.  Use
+       c_objc_common_truthvalue_conversion not
+       c_common_truthvalue_conversion.
+       (c_objc_common_truthvalue_conversion): Build NE_EXPR directly and
+       call note_integer_operands for arguments with integer operands
+       that are not integer constants.
+
 2012-09-20  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
index bd82d42..6dbb70e 100644 (file)
@@ -3642,7 +3642,13 @@ build_unary_op (location_t location,
                    "wrong type argument to unary exclamation mark");
          return error_mark_node;
        }
-      arg = c_objc_common_truthvalue_conversion (location, arg);
+      if (int_operands)
+       {
+         arg = c_objc_common_truthvalue_conversion (location, xarg);
+         arg = remove_c_maybe_const_expr (arg);
+       }
+      else
+       arg = c_objc_common_truthvalue_conversion (location, arg);
       ret = invert_truthvalue_loc (location, arg);
       /* If the TRUTH_NOT_EXPR has been folded, reset the location.  */
       if (EXPR_P (ret) && EXPR_HAS_LOCATION (ret))
@@ -9896,8 +9902,20 @@ build_binary_op (location_t location, enum tree_code code,
             but that does not mean the operands should be
             converted to ints!  */
          result_type = integer_type_node;
-         op0 = c_common_truthvalue_conversion (location, op0);
-         op1 = c_common_truthvalue_conversion (location, op1);
+         if (op0_int_operands)
+           {
+             op0 = c_objc_common_truthvalue_conversion (location, orig_op0);
+             op0 = remove_c_maybe_const_expr (op0);
+           }
+         else
+           op0 = c_objc_common_truthvalue_conversion (location, op0);
+         if (op1_int_operands)
+           {
+             op1 = c_objc_common_truthvalue_conversion (location, orig_op1);
+             op1 = remove_c_maybe_const_expr (op1);
+           }
+         else
+           op1 = c_objc_common_truthvalue_conversion (location, op1);
          converted = 1;
          boolean_op = true;
        }
@@ -10609,12 +10627,17 @@ c_objc_common_truthvalue_conversion (location_t location, tree expr)
 
   int_const = (TREE_CODE (expr) == INTEGER_CST && !TREE_OVERFLOW (expr));
   int_operands = EXPR_INT_CONST_OPERANDS (expr);
-  if (int_operands)
-    expr = remove_c_maybe_const_expr (expr);
-
-  /* ??? Should we also give an error for vectors rather than leaving
-     those to give errors later?  */
-  expr = c_common_truthvalue_conversion (location, expr);
+  if (int_operands && TREE_CODE (expr) != INTEGER_CST)
+    {
+      expr = remove_c_maybe_const_expr (expr);
+      expr = build2 (NE_EXPR, integer_type_node, expr,
+                    convert (TREE_TYPE (expr), integer_zero_node));
+      expr = note_integer_operands (expr);
+    }
+  else
+    /* ??? Should we also give an error for vectors rather than leaving
+       those to give errors later?  */
+    expr = c_common_truthvalue_conversion (location, expr);
 
   if (TREE_CODE (expr) == INTEGER_CST && int_operands && !int_const)
     {
index fee7540..b187ad7 100644 (file)
@@ -1,3 +1,14 @@
+2012-09-20  Joseph Myers  <joseph@codesourcery.com>
+
+       PR c/54103
+       * gcc.c-torture/compile/pr54103-1.c,
+       gcc.c-torture/compile/pr54103-2.c,
+       gcc.c-torture/compile/pr54103-3.c,
+       gcc.c-torture/compile/pr54103-4.c,
+       gcc.c-torture/compile/pr54103-5.c,
+       gcc.c-torture/compile/pr54103-6.c: New tests.
+       * gcc.dg/c90-const-expr-8.c: Update expected column number.
+
 2012-09-20  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr54103-1.c b/gcc/testsuite/gcc.c-torture/compile/pr54103-1.c
new file mode 100644 (file)
index 0000000..d941f3e
--- /dev/null
@@ -0,0 +1,5 @@
+void
+f (void)
+{
+  0 || 0 / 0 ? : 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr54103-2.c b/gcc/testsuite/gcc.c-torture/compile/pr54103-2.c
new file mode 100644 (file)
index 0000000..4bd6249
--- /dev/null
@@ -0,0 +1,5 @@
+void
+f (void)
+{
+  0 / 0 || 0 ? : 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr54103-3.c b/gcc/testsuite/gcc.c-torture/compile/pr54103-3.c
new file mode 100644 (file)
index 0000000..9be0b94
--- /dev/null
@@ -0,0 +1,5 @@
+void
+f (void)
+{
+  1 && 0 / 0 ? : 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr54103-4.c b/gcc/testsuite/gcc.c-torture/compile/pr54103-4.c
new file mode 100644 (file)
index 0000000..89ce24c
--- /dev/null
@@ -0,0 +1,5 @@
+void
+f (void)
+{
+  0 / 0 && 1 ? : 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr54103-5.c b/gcc/testsuite/gcc.c-torture/compile/pr54103-5.c
new file mode 100644 (file)
index 0000000..9594b28
--- /dev/null
@@ -0,0 +1,5 @@
+void
+f (void)
+{
+  !(0 / 0);
+}
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr54103-6.c b/gcc/testsuite/gcc.c-torture/compile/pr54103-6.c
new file mode 100644 (file)
index 0000000..2b0b0ba
--- /dev/null
@@ -0,0 +1,5 @@
+void
+f (void)
+{
+  0 || 65536*65536 ? : 0;
+}
index b00bb97..4923bc6 100644 (file)
@@ -22,6 +22,6 @@ enum e {
   E5 = 0 * -INT_MIN, /* { dg-warning "12:integer overflow in expression" } */
   /* { dg-error "3:overflow in constant expression" "constant" { target *-*-* } 22 } */
   E6 = 0 * !-INT_MIN, /* { dg-warning "13:integer overflow in expression" } */
-  /* { dg-error "3:not an integer constant" "constant" { target *-*-* } 24 } */
+  /* { dg-error "8:not an integer constant" "constant" { target *-*-* } 24 } */
   E7 = INT_MIN % -1 /* Not an overflow.  */
 };