]> gcc.gnu.org Git - gcc.git/commit
c, c++: Allow ignoring -Winit-self through pragmas [PR105593]
authorJakub Jelinek <jakub@redhat.com>
Mon, 16 Jan 2023 08:40:14 +0000 (09:40 +0100)
committerJakub Jelinek <jakub@redhat.com>
Mon, 16 Jan 2023 08:40:14 +0000 (09:40 +0100)
commit98b41fd4045b7856e7b85dd58d67c600bd909379
treef5994ab32fb6603a3d484310f23236379f30e92f
parent074b0c03eabeb8e9c8de813c81bf87a1f88fdb65
c, c++: Allow ignoring -Winit-self through pragmas [PR105593]

As mentioned in the PR, various x86 intrinsics need to return
an uninitialized vector.  Currently they use self initialization
to avoid -Wuninitialized warnings, which works fine in C, but
doesn't work in C++ where -Winit-self is enabled in -Wall.
We don't have an attribute to mark a variable as knowingly
uninitialized (the uninitialized attribute exists but means
something else, only in the -ftrivial-auto-var-init context),
and trying to suppress either -Wuninitialized or -Winit-self
inside of the _mm_undefined_ps etc. intrinsic definitions
doesn't work, one needs to currently disable through pragmas
-Wuninitialized warning at the point where _mm_undefined_ps etc.
result is actually used, but that goes against the intent of
those intrinsics.

The -Winit-self warning option actually doesn't do any warning,
all we do is record a suppression for -Winit-self if !warn_init_self
on the decl definition and later look that up in uninit pass.

The following patch changes those !warn_init_self tests which
are true only based on the command line option setting, not based
on GCC diagnostic pragma overrides to
!warning_enabled_at (DECL_SOURCE_LOCATION (decl), OPT_Winit_self)
such that it takes them into account.

2023-01-16  Jakub Jelinek  <jakub@redhat.com>

PR c++/105593
gcc/c/
* c-parser.cc (c_parser_initializer): Check warning_enabled_at
at the DECL_SOURCE_LOCATION (decl) for OPT_Winit_self instead
of warn_init_self.
gcc/cp/
* decl.cc (cp_finish_decl): Check warning_enabled_at
at the DECL_SOURCE_LOCATION (decl) for OPT_Winit_self instead
of warn_init_self.
gcc/testsuite/
* c-c++-common/Winit-self3.c: New test.
* c-c++-common/Winit-self4.c: New test.
* c-c++-common/Winit-self5.c: New test.
gcc/c/c-parser.cc
gcc/cp/decl.cc
gcc/testsuite/c-c++-common/Winit-self3.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Winit-self4.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/Winit-self5.c [new file with mode: 0644]
This page took 0.063842 seconds and 6 git commands to generate.