public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/97100] New: -Wformat checks all arms of _Generic leading to irrelevant type expectation warnings
@ 2020-09-18  0:56 sherzberg+gcc at freeshell dot org
  2023-07-17 12:11 ` [Bug c/97100] " Hi-Angel at yandex dot ru
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: sherzberg+gcc at freeshell dot org @ 2020-09-18  0:56 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 97100
           Summary: -Wformat checks all arms of _Generic leading to
                    irrelevant type expectation warnings
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sherzberg+gcc at freeshell dot org
  Target Milestone: ---

Created attachment 49238
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49238&action=edit
preprocessed output

The Wformat printf/scanf checker will produce warnings for all arms of a
generic expression, even those which will not be included in the program. This
can produce a fairly large number of warnings, since the macro below will
produce a warning for many of its arms for each use of the macro.

This is sort of code used in _Generic tutorials, and mostly nowhere else, that
can produce a large number of irrelevant warnings:

#define DISPLAY(x) \
    _Generic(x, int: printf("%d\r\n", x), \
                char: printf("%c\r\n", x), \
                float: printf("%.3f\r\n", x))


$ gcc-10 -v -save-temps -Wall generic_test.c 
Using built-in specs.
COLLECT_GCC=gcc-10
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu
10-20200411-0ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-10
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib --enable-libphobos-checking=release
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none,amdgcn-amdhsa,hsa --without-cuda-driver
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.0.1 20200411 (experimental) [master revision
bb87d5cc77d:75961caccb7:f883c46b4877f637e0fa5025b4d6b5c9040ec566] (Ubuntu
10-20200411-0ubuntu1) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/10/cc1 -E -quiet -v -imultiarch x86_64-linux-gnu
generic_test.c -mtune=generic -march=x86-64 -Wall -fpch-preprocess
-fasynchronous-unwind-tables -fstack-protector-strong -Wformat-security
-fstack-clash-protection -fcf-protection -o generic_test.i
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/10/include-fixed"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/10/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/10/cc1 -fpreprocessed generic_test.i -quiet
-dumpbase generic_test.c -mtune=generic -march=x86-64 -auxbase generic_test
-Wall -version -fasynchronous-unwind-tables -fstack-protector-strong
-Wformat-security -fstack-clash-protection -fcf-protection -o generic_test.s
GNU C17 (Ubuntu 10-20200411-0ubuntu1) version 10.0.1 20200411 (experimental)
[master revision
bb87d5cc77d:75961caccb7:f883c46b4877f637e0fa5025b4d6b5c9040ec566]
(x86_64-linux-gnu)
        compiled by GNU C version 10.0.1 20200411 (experimental) [master
revision bb87d5cc77d:75961caccb7:f883c46b4877f637e0fa5025b4d6b5c9040ec566], GMP
version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version
isl-0.22.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C17 (Ubuntu 10-20200411-0ubuntu1) version 10.0.1 20200411 (experimental)
[master revision
bb87d5cc77d:75961caccb7:f883c46b4877f637e0fa5025b4d6b5c9040ec566]
(x86_64-linux-gnu)
        compiled by GNU C version 10.0.1 20200411 (experimental) [master
revision bb87d5cc77d:75961caccb7:f883c46b4877f637e0fa5025b4d6b5c9040ec566], GMP
version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version
isl-0.22.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: d7d6d629e7a95e97eb10596483b5a39e
generic_test.c: In function ‘main’:
generic_test.c:10:32: warning: format ‘%d’ expects argument of type ‘int’, but
argument 2 has type ‘double’ [-Wformat=]
   10 |     DISPLAY(1.0f);
      |                                ^             
      |                                          |
      |                                          double
generic_test.c:10:62: warning: format ‘%c’ expects argument of type ‘int’, but
argument 2 has type ‘double’ [-Wformat=]
   10 |     DISPLAY(1.0f);
      |                                                              ^          
      |                                                                       
|
      |                                                                       
double
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-mtune=generic' '-march=x86-64'
 as -v --64 -o generic_test.o generic_test.s
GNU assembler version 2.34 (x86_64-linux-gnu) using BFD version (GNU Binutils
for Ubuntu) 2.34
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/10/collect2 -plugin
/usr/lib/gcc/x86_64-linux-gnu/10/liblto_plugin.so
-plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
-plugin-opt=-fresolution=generic_test.res -plugin-opt=-pass-through=-lgcc
-plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id
--eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker
/lib64/ld-linux-x86-64.so.2 -pie -z now -z relro
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/Scrt1.o
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crti.o
/usr/lib/gcc/x86_64-linux-gnu/10/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/10
-L/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu
-L/usr/lib/gcc/x86_64-linux-gnu/10/../../../../lib -L/lib/x86_64-linux-gnu
-L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib
-L/usr/lib/gcc/x86_64-linux-gnu/10/../../.. generic_test.o -lgcc --push-state
--as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s
--pop-state /usr/lib/gcc/x86_64-linux-gnu/10/crtendS.o
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crtn.o
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-Wall' '-mtune=generic' '-march=x86-64'

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2024-04-16  9:55 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-18  0:56 [Bug c/97100] New: -Wformat checks all arms of _Generic leading to irrelevant type expectation warnings sherzberg+gcc at freeshell dot org
2023-07-17 12:11 ` [Bug c/97100] " Hi-Angel at yandex dot ru
2023-08-04  6:06 ` muecker at gwdg dot de
2023-08-05  8:40 ` cvs-commit at gcc dot gnu.org
2023-11-03 19:26 ` uecker at gcc dot gnu.org
2024-04-16  3:07 ` alx at kernel dot org
2024-04-16  3:08 ` alx at kernel dot org
2024-04-16  5:35 ` uecker at gcc dot gnu.org
2024-04-16  5:58 ` Hi-Angel at yandex dot ru
2024-04-16  6:03 ` uecker at gcc dot gnu.org
2024-04-16  6:27 ` Hi-Angel at yandex dot ru
2024-04-16  7:02 ` muecker at gwdg dot de
2024-04-16  7:33 ` Hi-Angel at yandex dot ru
2024-04-16  8:23 ` muecker at gwdg dot de
2024-04-16  9:55 ` alx at kernel dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).