]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Revert:
authorbje <bje@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 28 Apr 2009 04:56:47 +0000 (04:56 +0000)
committerbje <bje@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 28 Apr 2009 04:56:47 +0000 (04:56 +0000)
PR c++/35652
2009-03-27  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>

gcc/
* builtins.c (c_strlen): Do not warn here.
* c-typeck.c (build_binary_op): Adjust calls to pointer_int_sum.
* c-common.c (pointer_int_sum): Take an explicit location.
Warn about offsets out of bounds.
* c-common.h (pointer_int_sum): Adjust declaration.

cp/
* typeck.c (cp_pointer_sum): Adjust call to pointer_int_sum.

testsuite/
* gcc.dg/pr35652.C: New.
* g++.dg/warn/pr35652.C: New.
* gcc.dg/format/plus-1.c: Adjust message.

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

gcc/ChangeLog
gcc/builtins.c
gcc/c-common.c
gcc/c-common.h
gcc/c-typeck.c
gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/warn/pr35652.C
gcc/testsuite/gcc.dg/format/plus-1.c
gcc/testsuite/gcc.dg/pr35652.c

index 74ff18560f95728299ce526990a430c7685c1adf..153e71b4f33040ac5d65fbba4b8c7acdf11b3a6a 100644 (file)
@@ -1,3 +1,16 @@
+2009-04-28  Ben Elliston  <bje@au.ibm.com>
+
+       PR c++/35652
+       Revert:
+
+       2009-03-27  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       * builtins.c (c_strlen): Do not warn here.
+       * c-typeck.c (build_binary_op): Adjust calls to pointer_int_sum.
+       * c-common.c (pointer_int_sum): Take an explicit location.
+       Warn about offsets out of bounds.
+       * c-common.h (pointer_int_sum): Adjust declaration.
+
 2009-04-27  Ian Lance Taylor  <iant@google.com>
 
        * collect2.c (is_ctor_dtor): Change type of ret field in struct
index 8621e0db5115e7dcad4e99837886fa0f101e56ff..067e3116faf266d98de457a26caf25d3e34b6a74 100644 (file)
@@ -479,13 +479,16 @@ c_strlen (tree src, int only_value)
   else
     offset = tree_low_cst (offset_node, 0);
 
-  /* If the offset is known to be out of bounds, the front-end should
-     have warned already. We call strlen at runtime.  
-
-     ??? Perhaps we should turn this into an assert and force
-     front-ends to define offsets whtin boundaries.  */
+  /* If the offset is known to be out of bounds, warn, and call strlen at
+     runtime.  */
   if (offset < 0 || offset > max)
     {
+     /* Suppress multiple warnings for propagated constant strings.  */
+      if (! TREE_NO_WARNING (src))
+        {
+          warning (0, "offset outside bounds of constant string");
+          TREE_NO_WARNING (src) = 1;
+        }
       return NULL_TREE;
     }
 
index 67fe8ad8ebd9718a538785c69700de5ff497609b..7ee7a091963e442f16777f9dfaa4391a674487f0 100644 (file)
@@ -3767,8 +3767,7 @@ shorten_compare (tree *op0_ptr, tree *op1_ptr, tree *restype_ptr,
    of pointer PTROP and integer INTOP.  */
 
 tree
-pointer_int_sum (location_t location, enum tree_code resultcode,
-                tree ptrop, tree intop)
+pointer_int_sum (enum tree_code resultcode, tree ptrop, tree intop)
 {
   tree size_exp, ret;
 
@@ -3777,19 +3776,19 @@ pointer_int_sum (location_t location, enum tree_code resultcode,
 
   if (TREE_CODE (TREE_TYPE (result_type)) == VOID_TYPE)
     {
-      pedwarn (location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, 
+      pedwarn (input_location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, 
               "pointer of type %<void *%> used in arithmetic");
       size_exp = integer_one_node;
     }
   else if (TREE_CODE (TREE_TYPE (result_type)) == FUNCTION_TYPE)
     {
-      pedwarn (location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, 
+      pedwarn (input_location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, 
               "pointer to a function used in arithmetic");
       size_exp = integer_one_node;
     }
   else if (TREE_CODE (TREE_TYPE (result_type)) == METHOD_TYPE)
     {
-      pedwarn (location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, 
+      pedwarn (input_location, pedantic ? OPT_pedantic : OPT_Wpointer_arith, 
               "pointer to member function used in arithmetic");
       size_exp = integer_one_node;
     }
@@ -3852,31 +3851,6 @@ pointer_int_sum (location_t location, enum tree_code resultcode,
   if (resultcode == MINUS_EXPR)
     intop = fold_build1 (NEGATE_EXPR, sizetype, intop);
 
-  if (TREE_CODE (intop) == INTEGER_CST)
-    {
-      tree offset_node;
-      tree string_cst = string_constant (ptrop, &offset_node);
-
-      if (string_cst != 0 
-         && !(offset_node && TREE_CODE (offset_node) != INTEGER_CST))
-       {
-         HOST_WIDE_INT max = TREE_STRING_LENGTH (string_cst);
-         HOST_WIDE_INT offset;
-         if (offset_node == 0)
-           offset = 0;
-         else if (! host_integerp (offset_node, 0))
-           offset = -1;
-         else
-           offset = tree_low_cst (offset_node, 0);
-
-         offset = offset + tree_low_cst (intop, 0);
-         if (offset < 0 || offset > max)
-           warning_at (location, 0,
-                       "offset %<%wd%> outside bounds of constant string",
-                       tree_low_cst (intop, 0));
-       }
-    }
-
   ret = fold_build2 (POINTER_PLUS_EXPR, result_type, ptrop, intop);
 
   fold_undefer_and_ignore_overflow_warnings ();
index 1e313cf9e8e1d8ec170068ce2bd69be365a09ca4..616273ad5c19825e8dedda3a9da05218f98bbb2f 100644 (file)
@@ -817,7 +817,7 @@ extern tree shorten_binary_op (tree result_type, tree op0, tree op1, bool bitwis
    and, if so, perhaps change them both back to their original type.  */
 extern tree shorten_compare (tree *, tree *, tree *, enum tree_code *);
 
-extern tree pointer_int_sum (location_t, enum tree_code, tree, tree);
+extern tree pointer_int_sum (enum tree_code, tree, tree);
 
 /* Add qualifiers to a type, in the fashion for C.  */
 extern tree c_build_qualified_type (tree, int);
index f5ee1ef8fd7458b55d87c33df3a5f0f17fec306a..88eb96a5bdb8c8eb000439933b37c8ee42bba1aa 100644 (file)
@@ -8882,12 +8882,12 @@ build_binary_op (location_t location, enum tree_code code,
       /* Handle the pointer + int case.  */
       if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
        {
-         ret = pointer_int_sum (location, PLUS_EXPR, op0, op1);
+         ret = pointer_int_sum (PLUS_EXPR, op0, op1);
          goto return_build_binary_op;
        }
       else if (code1 == POINTER_TYPE && code0 == INTEGER_TYPE)
        {
-         ret = pointer_int_sum (location, PLUS_EXPR, op1, op0);
+         ret = pointer_int_sum (PLUS_EXPR, op1, op0);
          goto return_build_binary_op;
        }
       else
@@ -8906,7 +8906,7 @@ build_binary_op (location_t location, enum tree_code code,
       /* Handle pointer minus int.  Just like pointer plus int.  */
       else if (code0 == POINTER_TYPE && code1 == INTEGER_TYPE)
        {
-         ret = pointer_int_sum (location, MINUS_EXPR, op0, op1);
+         ret = pointer_int_sum (MINUS_EXPR, op0, op1);
          goto return_build_binary_op;
        }
       else
index 95aff1f542d8472d6a5f16b9ce7f2dff573e1c06..710484b582efb69829da480ba88460dd1ba55ecf 100644 (file)
@@ -1,3 +1,12 @@
+2009-04-28  Ben Elliston  <bje@au.ibm.com>
+
+       PR c++/35652
+       Revert:
+
+       2009-03-27  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       * typeck.c (cp_pointer_sum): Adjust call to pointer_int_sum.
+
 2009-04-27  Ian Lance Taylor  <iant@google.com>
 
        * semantics.c (finish_omp_clauses): Change type of c_kind to enum
index 69d5529476d1d60de973e41b085925c1b455320c..5486c546b6810487d79667de9a75923fafcfb437 100644 (file)
@@ -4054,7 +4054,7 @@ cp_pointer_int_sum (enum tree_code resultcode, tree ptrop, tree intop)
      pointer_int_sum() anyway.  */
   complete_type (TREE_TYPE (res_type));
 
-  return pointer_int_sum (input_location, resultcode, ptrop,
+  return pointer_int_sum (resultcode, ptrop,
                          fold_if_not_in_template (intop));
 }
 
index 3bd76ade30214fef75437a40e6c9d49aebc965af..777922bcbea8b68540a995fe6f6e62774a5d29c3 100644 (file)
@@ -1,3 +1,14 @@
+2009-04-28  Ben Elliston  <bje@au.ibm.com>
+
+       PR c++/35652
+       Revert:
+
+       2009-03-27  Manuel Lopez-Ibanez  <manu@gcc.gnu.org>
+
+       * gcc.dg/pr35652.C: New.
+       * g++.dg/warn/pr35652.C: New.
+       * gcc.dg/format/plus-1.c: Adjust message.
+
 2009-04-27  DJ Delorie  <dj@redhat.com>
 
        * lib/target-supports.exp (check_effective_target_double64): New.
index 7ce9431eb2be11580a4c04e89b8f0f130c2ceaaa..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1,30 +0,0 @@
-// PR c++/35652: wrong location and duplicated warning.
-// { dg-do compile }
-// { dg-options "-fshow-column" }
-#include <string>
-int foo() {
-  // blank line padding, could also be code...
-  //
-  //
-  //
-  //
-  //
-  //
-  //
-  //
-  //
-  std::string s = "";
-  s += 'x' + "y";  // { dg-warning "14:offset '120' outside bounds of constant string" }
-  // { dg-bogus "offset '120' outside bounds of constant string.*offset '120' outside bounds of constant string" "duplicated" { target *-*-* } 17 }
-}
-
-int bar()
-{
-  const char *s = 'z' + "y"; /* { dg-warning "25:offset '122' outside bounds of constant string" } */
-}
-
-int g()
-{
-  char str[2];
-  const char *p = str + sizeof(str);
-}
index 0d8b62cd3c5fe394145b9f6bdaedf0ca7d093cef..02a213d417dc1dc99d65bc7d941c5be0bfcf883a 100644 (file)
@@ -15,9 +15,6 @@ foo (int i)
   printf (3 + "%d\n");         /* { dg-warning "zero-length" "zero-length string" } */
   printf ("%d\n" + i, i);      /* { dg-warning "not a string" "non-constant addend" } */
   printf ("%d\n" + 10);                /* { dg-warning "not a string" "too large addend" } */
-                                /* { dg-warning "offset '10' outside bounds of constant string" "offset" { target *-*-* } 17 } */
   printf ("%d\n" - 1, i);      /* { dg-warning "not a string" "minus constant" } */
-                                /* { dg-warning "offset '-1' outside bounds of constant string" "offset" { target *-*-* } 19 } */
   printf ("%d\n" + -1, i);     /* { dg-warning "not a string" "negative addend" } */
-                                /* { dg-warning "offset '-1' outside bounds of constant string" "offset" { target *-*-* } 21 } */
 }
index 50ec3acf10a6532b7029f1f8fc9fcd324febbe4c..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 100644 (file)
@@ -1,13 +0,0 @@
-/* PR c++/35652: wrong location and duplicated warning.
- { dg-do compile }
- { dg-options "" } */
-int bar()
-{
-  const char *s = 'z' + "y"; /* { dg-warning "offset '122' outside bounds of constant string" } */
-}
-
-int g()
-{
-  char str[2];
-  const char *p = str + sizeof(str);
-}