Bug 105210 - gcc/auto-profile.cc:391:11: warning: variable 'level' set but not used
Summary: gcc/auto-profile.cc:391:11: warning: variable 'level' set but not used
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: gcov-profile (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: 13.0
Assignee: Martin Liška
URL:
Keywords: diagnostic
Depends on:
Blocks: Wunused
  Show dependency treegraph
 
Reported: 2022-04-10 19:54 UTC by David Binderman
Modified: 2022-05-05 18:31 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2022-04-11 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Binderman 2022-04-10 19:54:31 UTC
A compile of recent gcc trunk with clang trunk shows
that local variable level is set but not used.

$ fgrep level ../trunk.git/gcc/auto-profile.cc
          level information (not source level). This info is used to help
     This will be enforced when instruction-level discriminator
        function is a top-level function_instance, i.e. it is the original copy
  /* For a given DECL, returns the top-level function_instance.  */
      int level = 0;
          level++;
/* For a given DECL, returns the top-level function_instance.  */
$ 

Suggest remove local variable.
Comment 1 David Binderman 2022-04-10 20:04:46 UTC
It would appear that clang trunk is better at finding set-but-not-used
variables than gcc.

Here are some more cases:

./../trunk.git/gcc/genautomata.cc:5664:7: warning: variable 'alts_number' set but not used [-Wunused-but-set-variable]
../../trunk.git/gcc/graphite-poly.cc:344:7: warning: variable 'nb_reads' set but not used [-Wunused-but-set-variable]
../../trunk.git/gcc/graphite-poly.cc:345:7: warning: variable 'nb_writes' set but not used [-Wunused-but-set-variable]
../../trunk.git/gcc/lto-wrapper.cc:1428:12: warning: variable 'n_debugobj' set but not used [-Wunused-but-set-variable]
../../trunk.git/libdecnumber/dpd/decimal64.c:617:8: warning: variable 'n' set but not used [-Wunused-but-set-variable]
../../trunk.git/gcc/tree-switch-conversion.cc:2042:11: warning: variable 'ranges' set but not used [-Wunused-but-set-variable]

I am not sure if these variables are candidates for deletion, or some code
should be using them.
Comment 2 David Binderman 2022-04-10 20:12:17 UTC
It seems that recent gcc trunk can't detect set-but-not-used in this code:

extern int g( int);

void f( int m)
{
	int n;

	n = 0;

	for (int i = 0; i < m; ++i)
	{
		if (g( i))
		{
			++n;
		}
	}
}

$ /home/dcb/gcc/results/bin/g++ -c -g -O2  -Wall -Wextra -pedantic apr10b.cc
$

Recent clang trunk can:

$ /home/dcb/llvm/results/bin/clang++ -c -g -O2  -Wall  apr10b.cc
apr10b.cc:8:6: warning: variable 'n' set but not used [-Wunused-but-set-variable]
        int n;
            ^
1 warning generated.
$
Comment 3 Andrew Pinski 2022-04-10 21:58:53 UTC
(In reply to David Binderman from comment #2)
> It seems that recent gcc trunk can't detect set-but-not-used in this code:

There is another bug about this already but I can't find that one right now; it might have been closed as won't fix or invalid (I can't remember).
Comment 4 Eric Gallager 2022-04-10 22:10:08 UTC
(In reply to Andrew Pinski from comment #3)
> (In reply to David Binderman from comment #2)
> > It seems that recent gcc trunk can't detect set-but-not-used in this code:
> 
> There is another bug about this already but I can't find that one right now

bug 44677?
Comment 5 Andrew Pinski 2022-04-10 22:29:43 UTC
(In reply to Eric Gallager from comment #4)
> (In reply to Andrew Pinski from comment #3)
> > (In reply to David Binderman from comment #2)
> > > It seems that recent gcc trunk can't detect set-but-not-used in this code:
> > 
> > There is another bug about this already but I can't find that one right now
> 
> bug 44677?

Yes that one.
Comment 6 Martin Liška 2022-04-11 08:13:00 UTC
I'm going to prepare a patch for next stage 1.
Comment 7 David Binderman 2022-04-12 17:56:16 UTC
(In reply to Martin Liška from comment #6)
> I'm going to prepare a patch for next stage 1.

Do you mean the smaller patch to fix the problems I reported,
or a larger patch to have gcc duplicate the behaviour of clang ?

I checked the assembly language output from the code in comment 2
and AFAIK the optimiser removes the pointless increment at level -O1
and above.
Comment 8 Martin Liška 2022-04-12 18:45:36 UTC
> Do you mean the smaller patch to fix the problems I reported,
> or a larger patch to have gcc duplicate the behaviour of clang ?

Yes, the former one.
Comment 9 Martin Liška 2022-05-05 13:05:32 UTC
Should be fixed with g:880456ed99d23ae76be4ecc929bcbcf8cae5eb66.
Comment 10 David Binderman 2022-05-05 15:43:57 UTC
(In reply to Martin Liška from comment #9)
> Should be fixed with g:880456ed99d23ae76be4ecc929bcbcf8cae5eb66.

Presumably there's a good reason why the one in file libdecnumber/dpd/decimal64.c
didn't get fixed ?
Comment 11 Martin Liška 2022-05-05 18:31:16 UTC
> Presumably there's a good reason why the one in file
> libdecnumber/dpd/decimal64.c
> didn't get fixed ?

It's pretty legacy code out of gcc folder, so that's the reason ;)