Bootstrap with -Wno-restrict fails due to -Werror=unused-but-set-variable in gcc/gcov.c: /src/gcc/svn/gcc/gcov.c: In function ‘const char* format_count(gcov_type)’: /src//gcc/svn/gcc/gcov.c:2328:9: warning: variable ‘r’ set but not used [-Wunused-but-set-variable] 2328 | float r = 1.0f * count / divisor; | ^ A small test case reduced from the file is as follows. This is not reproducible with the C front-end: $ cat t.c && gcc -O2 -S -Wall -Wextra -Wno-restrict -xc++ t.c extern "C" int printf (const char*, ...); void f (unsigned n) { int i = 0; while (n >>= 1) ++i; float r = 1.0f * i; printf ("%f", r); } t.c: In function ‘void f(unsigned int)’: t.c:8:9: warning: variable ‘r’ set but not used [-Wunused-but-set-variable] 8 | float r = 1.0f * i; | ^
I thought the problem was introduced with -Wrestrict but it looks like the false positive is actually a regression caused by r276059: r276059 | jason | 2019-09-23 13:48:00 -0400 (Mon, 23 Sep 2019) | 10 lines PR c++/91809 - bit-field and ellipsis. decay_conversion converts a bit-field access to its declared type, which isn't what we want here; it even has a comment that the caller is expected to have already used default_conversion to perform integral promotion. This function handles arithmetic promotion differently, but we still don't want to call decay_conversion before that happens. * call.c (convert_arg_to_ellipsis): Don't call decay_conversion for arithmetic arguments.
The check_function_restrict() function is called to do the -Wrestrict checking. It's called conditionally, from check_function_arguments(), when warn_restrict is nonzero. When called, the function calls fold_for_warn() for all arguments of the functions it checks for aliasing violations. fold_for_warn() ends up calling mark_rvalue_use() which ultimately calls mark_exp_read() which sets DECL_READ_P (exp) = 1 for VAR_DECL and PARM_DECL. None of this happens when -Wno-restrict is set.
Created attachment 47521 [details] gcc10-pr92666.patch Untested fix. Code inspection revealed a wrong-code bug too.
Author: jakub Date: Fri Dec 20 23:16:58 2019 New Revision: 279681 URL: https://gcc.gnu.org/viewcvs?rev=279681&root=gcc&view=rev Log: PR c++/92666 * call.c (convert_arg_to_ellipsis): For floating point or decltype(nullptr) arguments call mark_rvalue_use. * g++.dg/warn/Wunused-var-36.C: New test. Added: trunk/gcc/testsuite/g++.dg/warn/Wunused-var-36.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/call.c trunk/gcc/testsuite/ChangeLog
Fixed (although the wrong-code fix needs to be backported).