This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug tree-optimization/86223] missing -Warray-bounds on an access to an implicitly zeroed out array


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86223

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
That's because of

        else if (!complete_p)
          /* If the constructor isn't complete, clear the whole object
             beforehand, unless CONSTRUCTOR_NO_CLEARING is set on it.

             ??? This ought not to be needed.  For any element not present
             in the initializer, we should simply set them to zero.  Except
             we'd need to *find* the elements that are not present, and that
             requires trickery to avoid quadratic compile-time behavior in
             large cases or excessive memory use in small cases.  */
          cleared = !CONSTRUCTOR_NO_CLEARING (ctor);

but for the complete case

        else if (num_ctor_elements - num_nonzero_elements
                 > CLEAR_RATIO (optimize_function_for_speed_p (cfun))
                 && num_nonzero_elements < num_ctor_elements / 4)
          /* If there are "lots" of zeros, it's more efficient to clear
             the memory and then set the nonzero elements.  */
          cleared = true;

doesn't trigger.  I believe that the gimplifier deciding on elementwise
vs. copy-from-initializer is premature (but that's another story).

So to make the behavior consistent the easiest approach would be to
emit {} for all-zero initializers always.  Not sure if that's the best
for optimization.  A different fix would be to fix that ??? comment.

diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 97543ed5f70..ccdc127143d 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -4805,6 +4805,10 @@ gimplify_init_constructor (tree *expr_p, gimple_seq
*pre_p, gimple_seq *post_p,
             requires trickery to avoid quadratic compile-time behavior in
             large cases or excessive memory use in small cases.  */
          cleared = !CONSTRUCTOR_NO_CLEARING (ctor);
+       else if (num_nonzero_elements == 0)
+         /* If all elements are zero it is most efficient to block-clear
+            things.  */
+         cleared = true;
        else if (num_ctor_elements - num_nonzero_elements
                 > CLEAR_RATIO (optimize_function_for_speed_p (cfun))
                 && num_nonzero_elements < num_ctor_elements / 4)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]