Fixing PR107411
authorQing Zhao <qing.zhao@oracle.com>
Tue, 28 Feb 2023 17:11:05 +0000 (17:11 +0000)
committerQing Zhao <qing.zhao@oracle.com>
Tue, 28 Feb 2023 17:11:05 +0000 (17:11 +0000)
commitafe6cea4489846aa8585f3c045d16cdaa08cc6cd
treecab3f29c0fd562f30d4adcc05e7a685ca604f5ac
parent62ed1066196c81ab1fad13b2cc5ebbfe887138f9
Fixing PR107411

This is a bug in tree-ssa-uninit.cc.
When doing the following:

  /* Ignore the call to .DEFERRED_INIT that define the original
     var itself as the following case:
       temp = .DEFERRED_INIT (4, 2, “alt_reloc");
       alt_reloc = temp;
     In order to avoid generating warning for the fake usage
     at alt_reloc = temp.
  */

We need to compare the var name inside the .DEFERRED_INIT call
(the 3rd argument) and the name for the LHS variable. if they are the same,
we will NOT report the warning.

There is one issue when we get the name for the LHS variable. when the
variable doesn't have a DECL_NAME (it's not a user declared variable,
which is the case for this bug):

  _1 = .DEFERRED_INIT (4, 2, &"D.2389"[0]);
  D.2389 = _1;

The current checking just ignores this case, and still report the warning.

The fix is very simple, when getting the name for the LHS variable, we should
consider this case and come up with the name the same way as we construct the
3rd argument for the call to .DEFERRED_INIT (please refer to the routine
"gimple_add_init_for_auto_var")

PR middle-end/107411

gcc/ChangeLog:

PR middle-end/107411
* gimplify.cc (gimple_add_init_for_auto_var): Use sprintf to replace
xasprintf.
* tree-ssa-uninit.cc (warn_uninit): Handle the case when the
LHS varaible of a .DEFERRED_INIT call doesn't have a DECL_NAME.

gcc/testsuite/ChangeLog:

PR middle-end/107411
* g++.dg/pr107411.C: New test.
gcc/gimplify.cc
gcc/testsuite/g++.dg/pr107411.C [new file with mode: 0644]
gcc/tree-ssa-uninit.cc