diff mbox series

[committed] Cleanup structure initialization in preparation for fixing string length range computations

Message ID 13cbb8bc-e6ae-c990-7e14-c25d2c10a1a9@redhat.com
State New
Headers show
Series [committed] Cleanup structure initialization in preparation for fixing string length range computations | expand

Commit Message

Jeff Law Dec. 23, 2018, 3:39 p.m. UTC
So I'm working to break down and resubmit Martin's work to fix the
over-aggressive string length range computations.  There's a fair amount
of cleanup and other non-behavorial changes in that work.

There's two paths we could take.  One would be to drop all the
non-behavorial changes and reduce the patch down to just the fixes.
Sometimes this is my preferred route, but not this time.

With Martin out, I want the end result to look at much like his work as
possible to avoid introducing errors.  So culling out the non-behavorial
stuff will make comparing the end result to Martin's patch from Nov
essentially impossible.  Additionally, the non-behaviorial changes are
generally things we want to fix anyway.

So instead I'm going to break out the non-behavorial stuff, get it
installed, give the testers a day to build them (beyond my own standard
bootstrap/regression testing).  Then I'll work my way into the meat of
Martin's fixes.

Sooo..

This is the first of the non-behaviorial changes from Martin.  When I
introduced c_strlen_data to make our API more easily extendable, I used
memset for the structure initialization.  Using empty brace
initialization just seems cleaner.  I originally considered it, but got
it in my head that it wasn't supported in some case.  Maybe I was stuck
in a C mentality rather than C++.. :-)

This patch extracts Martin's work to convert the existing memset calls
in this space to instead use empty brace initialization.

None of these changes should affect the behavior of the resultant
compiler.  Bootstrapped and regression tested on x86_64.  Installing on
the trunk.  My tester will pick this up over the next 24hrs.

Committed to the trunk.


Jeff
commit 6f2fa95d8a2b62ffccddd23c6b04cef26b612d2a
Author: Jeff Law <law@redhat.com>
Date:   Fri Dec 21 16:55:19 2018 -0700

    2018-12-23  Martin Sebor  <msebor@redhat.com>
                Jeff Law  <law@redhat.com>
    
            * builtins.c (unterminated_array): Use empty brace initialization
            for c_strlen_data.
            (c_strlen, expand_builtin_strnlen): Likewise.
            (expand_builtin_stpcpy_1, fold_builtin_strlen): Likewise.
            * gimple-fold.c (get_range_strlen): Likewise.
            (gimple_fold_builtin_stpcpy): Likewise.
            * gimple-ssa-sprintf.c (get_string_length): Likewise.
diff mbox series

Patch

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c15a1a43e6c..a63e7745536 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,14 @@ 
+2018-12-23  Martin Sebor  <msebor@redhat.com>
+	    Jeff Law  <law@redhat.com>
+
+	* builtins.c (unterminated_array): Use empty brace initialization
+	for c_strlen_data.
+	(c_strlen, expand_builtin_strnlen): Likewise.
+	(expand_builtin_stpcpy_1, fold_builtin_strlen): Likewise.
+	* gimple-fold.c (get_range_strlen): Likewise.
+	(gimple_fold_builtin_stpcpy): Likewise.
+	* gimple-ssa-sprintf.c (get_string_length): Likewise.
+
 2018-12-23  Alan Modra  <amodra@gmail.com>
 
 	PR 88346
diff --git a/gcc/builtins.c b/gcc/builtins.c
index 669e548706f..4a82f58d5f4 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -575,8 +575,7 @@  unterminated_array (tree exp, tree *size /* = NULL */, bool *exact /* = NULL */)
 {
   /* C_STRLEN will return NULL and set DECL in the info
      structure if EXP references a unterminated array.  */
-  c_strlen_data data;
-  memset (&data, 0, sizeof (c_strlen_data));
+  c_strlen_data data = { };
   tree len = c_strlen (exp, 1, &data);
   if (len == NULL_TREE && data.len && data.decl)
      {
@@ -647,8 +646,7 @@  c_strlen (tree src, int only_value, c_strlen_data *data, unsigned eltsize)
   /* If we were not passed a DATA pointer, then get one to a local
      structure.  That avoids having to check DATA for NULL before
      each time we want to use it.  */
-  c_strlen_data local_strlen_data;
-  memset (&local_strlen_data, 0, sizeof (c_strlen_data));
+  c_strlen_data local_strlen_data = { };
   if (!data)
     data = &local_strlen_data;
 
@@ -3085,8 +3083,7 @@  expand_builtin_strnlen (tree exp, rtx target, machine_mode target_mode)
 
   /* FIXME: Change c_strlen() to return sizetype instead of ssizetype
      so these conversions aren't necessary.  */
-  c_strlen_data data;
-  memset (&data, 0, sizeof (c_strlen_data));
+  c_strlen_data data { };
   tree len = c_strlen (src, 0, &data, 1);
   if (len)
     len = fold_convert_loc (loc, TREE_TYPE (bound), len);
@@ -4086,8 +4083,7 @@  expand_builtin_stpcpy_1 (tree exp, rtx target, machine_mode mode)
 	 compile-time, not an expression containing a string.  This is
 	 because the latter will potentially produce pessimized code
 	 when used to produce the return value.  */
-      c_strlen_data data;
-      memset (&data, 0, sizeof (c_strlen_data));
+      c_strlen_data data = { };
       if (!c_getstr (src, NULL)
 	  || !(len = c_strlen (src, 0, &data, 1)))
 	return expand_movstr (dst, src, target,
@@ -8571,8 +8567,7 @@  fold_builtin_strlen (location_t loc, tree type, tree arg)
     return NULL_TREE;
   else
     {
-      c_strlen_data data;
-      memset (&data, 0, sizeof (c_strlen_data));
+      c_strlen_data data = { };
       tree len = c_strlen (arg, 0, &data);
 
       if (len)
diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
index 67c8cfa4f64..af509740bb3 100644
--- a/gcc/gimple-fold.c
+++ b/gcc/gimple-fold.c
@@ -1335,8 +1335,7 @@  get_range_strlen (tree arg, tree length[2], bitmap *visited, int type,
 	}
       else
 	{
-	  c_strlen_data data;
-	  memset (&data, 0, sizeof (c_strlen_data));
+	  c_strlen_data data = { };
 	  val = c_strlen (arg, 1, &data, eltsize);
 
 	  /* If we potentially had a non-terminated string, then
@@ -2824,8 +2823,7 @@  gimple_fold_builtin_stpcpy (gimple_stmt_iterator *gsi)
     }
 
   /* Set to non-null if ARG refers to an unterminated array.  */
-  c_strlen_data data;
-  memset (&data, 0, sizeof (c_strlen_data));
+  c_strlen_data data = { };
   tree len = c_strlen (src, 1, &data, 1);
   if (!len
       || TREE_CODE (len) != INTEGER_CST)
diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c
index 52286a6da1c..d6278305fc4 100644
--- a/gcc/gimple-ssa-sprintf.c
+++ b/gcc/gimple-ssa-sprintf.c
@@ -2003,8 +2003,7 @@  get_string_length (tree str, unsigned eltsize)
   if (!str)
     return fmtresult ();
 
-  c_strlen_data data;
-  memset (&data, 0, sizeof (c_strlen_data));
+  c_strlen_data data = { };
   tree slen = c_strlen (str, 1, &data, eltsize);
   if (slen && TREE_CODE (slen) == INTEGER_CST)
     {