]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR tree-optimization/59362
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 3 Dec 2013 07:48:58 +0000 (07:48 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 3 Dec 2013 07:48:58 +0000 (07:48 +0000)
* tree-object-size.c (object_sizes): Change into array of
vec<unsigned HOST_WIDE_INT>.
(compute_builtin_object_size): Check computed bitmap for
non-NULL instead of object_sizes.  Call safe_grow on object_sizes
vector if new SSA_NAMEs appeared.
(init_object_sizes): Check computed bitmap for non-NULL.
Call safe_grow on object_sizes elements instead of initializing
it with XNEWVEC.
(fini_object_sizes): Call release on object_sizes elements, don't
set it to NULL.

* gcc.c-torture/compile/pr59362.c: New test.

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

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/pr59362.c [new file with mode: 0644]
gcc/tree-object-size.c

index 1f006954e4febf0d92cb9df1e498cbc1f043f259..de5799c1a36ded064b11a8b2b2808a0dc4991a18 100644 (file)
@@ -1,5 +1,17 @@
 2013-12-03  Jakub Jelinek  <jakub@redhat.com>
 
+       PR tree-optimization/59362
+       * tree-object-size.c (object_sizes): Change into array of
+       vec<unsigned HOST_WIDE_INT>.
+       (compute_builtin_object_size): Check computed bitmap for
+       non-NULL instead of object_sizes.  Call safe_grow on object_sizes
+       vector if new SSA_NAMEs appeared.
+       (init_object_sizes): Check computed bitmap for non-NULL.
+       Call safe_grow on object_sizes elements instead of initializing
+       it with XNEWVEC.
+       (fini_object_sizes): Call release on object_sizes elements, don't
+       set it to NULL.
+
        PR middle-end/59011
        * gimplify.c (nonlocal_vla_vars): New variable.
        (gimplify_var_or_parm_decl): Put VAR_DECLs for VLAs into
index fe6f94bade384f8c96551196941936dbfeaf9697..4fd97ac07afb1e9dd63c64d4ea1d5dfac619ce2b 100644 (file)
@@ -1,5 +1,8 @@
 2013-12-03  Jakub Jelinek  <jakub@redhat.com>
 
+       PR tree-optimization/59362
+       * gcc.c-torture/compile/pr59362.c: New test.
+
        PR middle-end/59011
        * gcc.dg/pr59011.c: New test.
 
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr59362.c b/gcc/testsuite/gcc.c-torture/compile/pr59362.c
new file mode 100644 (file)
index 0000000..3e78f76
--- /dev/null
@@ -0,0 +1,21 @@
+/* PR tree-optimization/59362 */
+
+char *
+foo (char *r, int s)
+{
+  r = __builtin___stpcpy_chk (r, "abc", __builtin_object_size (r, 1));
+  if (s)
+    r = __builtin___stpcpy_chk (r, "d", __builtin_object_size (r, 1));
+  return r;
+}
+
+char *a;
+long int b;
+
+void
+bar (void)
+{
+  b = __builtin_object_size (0, 0);
+  a = __builtin___stpcpy_chk (0, "", b);
+  b = __builtin_object_size (a, 0);
+}
index c9d5264fef62355b6e4855fcab8f91ba2befbadc..6a587e16c98f11ea12838466df2dfa18ef18e920 100644 (file)
@@ -78,7 +78,7 @@ static void check_for_plus_in_loops_1 (struct object_size_info *, tree,
    the subobject (innermost array or field with address taken).
    object_sizes[2] is lower bound for number of bytes till the end of
    the object and object_sizes[3] lower bound for subobject.  */
-static unsigned HOST_WIDE_INT *object_sizes[4];
+static vec<unsigned HOST_WIDE_INT> object_sizes[4];
 
 /* Bitmaps what object sizes have been computed already.  */
 static bitmap computed[4];
@@ -506,7 +506,7 @@ compute_builtin_object_size (tree ptr, int object_size_type)
 
   if (TREE_CODE (ptr) == SSA_NAME
       && POINTER_TYPE_P (TREE_TYPE (ptr))
-      && object_sizes[object_size_type] != NULL)
+      && computed[object_size_type] != NULL)
     {
       if (!bitmap_bit_p (computed[object_size_type], SSA_NAME_VERSION (ptr)))
        {
@@ -514,6 +514,8 @@ compute_builtin_object_size (tree ptr, int object_size_type)
          bitmap_iterator bi;
          unsigned int i;
 
+         if (num_ssa_names > object_sizes[object_size_type].length ())
+           object_sizes[object_size_type].safe_grow (num_ssa_names);
          if (dump_file)
            {
              fprintf (dump_file, "Computing %s %sobject size for ",
@@ -1175,12 +1177,12 @@ init_object_sizes (void)
 {
   int object_size_type;
 
-  if (object_sizes[0])
+  if (computed[0])
     return;
 
   for (object_size_type = 0; object_size_type <= 3; object_size_type++)
     {
-      object_sizes[object_size_type] = XNEWVEC (unsigned HOST_WIDE_INT, num_ssa_names);
+      object_sizes[object_size_type].safe_grow (num_ssa_names);
       computed[object_size_type] = BITMAP_ALLOC (NULL);
     }
 
@@ -1197,9 +1199,8 @@ fini_object_sizes (void)
 
   for (object_size_type = 0; object_size_type <= 3; object_size_type++)
     {
-      free (object_sizes[object_size_type]);
+      object_sizes[object_size_type].release ();
       BITMAP_FREE (computed[object_size_type]);
-      object_sizes[object_size_type] = NULL;
     }
 }