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

--- Comment #2 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
Ok, so the warning is triggering when uninitialized memory is passed to
function argument declared as const.  This happens here but is false positive
since the parameter is not used at all.  This may have become worse with EAF
analysis since we now optimize the dead code initializing unused parameters in
case kill analysis triggers.

Following patch fixes it but I do not understand why this does not trigger on
x86-64 for me.

diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c
index f23514395e0..1e074793b02 100644
--- a/gcc/tree-ssa-uninit.c
+++ b/gcc/tree-ssa-uninit.c
@@ -443,7 +443,7 @@ maybe_warn_operand (ao_ref &ref, gimple *stmt, tree lhs,
tree rhs,
    access implying read access to those objects.  */

 static void
-maybe_warn_pass_by_reference (gimple *stmt, wlimits &wlims)
+maybe_warn_pass_by_reference (gcall *stmt, wlimits &wlims)
 {
   if (!wlims.wmaybe_uninit)
     return;
@@ -501,6 +501,10 @@ maybe_warn_pass_by_reference (gimple *stmt, wlimits
&wlims)
              && !TYPE_READONLY (TREE_TYPE (argtype)))
            continue;

+         /* Ignore args we are not going to read from.  */
+         if (gimple_call_arg_flags (stmt, argno - 1) & EAF_UNUSED)
+           continue;
+
          if (save_always_executed && access->mode == access_read_only)
            /* Attribute read_only arguments imply read access.  */
            wlims.always_executed = true;
@@ -639,8 +643,8 @@ warn_uninitialized_vars (bool wmaybe_uninit)
          if (gimple_vdef (stmt))
            wlims.vdef_cnt++;

-         if (is_gimple_call (stmt))
-           maybe_warn_pass_by_reference (stmt, wlims);
+         if (gcall *call = dyn_cast <gcall *> (stmt))
+           maybe_warn_pass_by_reference (call, wlims);
          else if (gimple_assign_load_p (stmt)
                   && gimple_has_location (stmt))
            {

Reply via email to