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.
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.
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. $
(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).
(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?
(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.
I'm going to prepare a patch for next stage 1.
(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.
> 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.
Should be fixed with g:880456ed99d23ae76be4ecc929bcbcf8cae5eb66.
(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 ?
> 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 ;)