This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: Oh dear. I regret to inform you that commit 'RAII-fy make_cleanup_restore_current_thread & friends' might be unfortunate
- From: Pedro Alves <palves at redhat dot com>
- To: Simon Marchi <simon dot marchi at polymtl dot ca>
- Cc: gdb-patches at sourceware dot org
- Date: Thu, 4 May 2017 19:22:58 +0100
- Subject: Re: Oh dear. I regret to inform you that commit 'RAII-fy make_cleanup_restore_current_thread & friends' might be unfortunate
- Authentication-results: sourceware.org; auth=none
- References: <E1d6JGc-0000zB-OE@kwanyin.sergiodj.net> <34792dd0-088c-a1d1-9125-70c8585c21bd@redhat.com> <6bf88edee0fb17451d44b85bb00fb0d0@polymtl.ca>
On 05/04/2017 07:15 PM, Simon Marchi wrote:
> On 2017-05-04 12:42, Pedro Alves wrote:
>> On 05/04/2017 05:06 PM, gdb-buildbot@sergiodj.net wrote:
>>> g++ -g -O2 -I. -I../../binutils-gdb/gdb
>>> -I../../binutils-gdb/gdb/common -I../../binutils-gdb/gdb/config
>>> -DLOCALEDIR="\"/usr/local/share/locale\"" -DHAVE_CONFIG_H
>>> -I../../binutils-gdb/gdb/../include/opcode
>>> -I../../binutils-gdb/gdb/../opcodes/..
>>> -I../../binutils-gdb/gdb/../readline/..
>>> -I../../binutils-gdb/gdb/../zlib -I../bfd
>>> -I../../binutils-gdb/gdb/../bfd -I../../binutils-gdb/gdb/../include
>>> -I../libdecnumber -I../../binutils-gdb/gdb/../libdecnumber
>>> -I../../binutils-gdb/gdb/gnulib/import -Ibuild-gnulib/import
>>> -DTUI=1 -pthread -I/usr/include/guile/2.0 -I/usr/include/python2.7
>>> -I/usr/include/python2.7 -Wall -Wpointer-arith -Wno-unused
>>> -Wunused-value -Wunused-function -Wno-switch -Wno-char-subscripts
>>> -Wempty-body -Wunused-but-set-parameter -Wunused-but-set-variable
>>> -Wno-sign-compare -Wno-narrowing -Wformat-nonliteral -Werror -c -o
>>> interps.o -MT interps.o -MMD -MP -MF .deps/interps.Tpo
>>> ../../binutils-gdb/gdb/interps.c
>>> In file included from ../../binutils-gdb/gdb/infrun.c:26:0:
>>> ../../binutils-gdb/gdb/inferior.h: In function void
>>> handle_vfork_child_exec_or_exit(int):
>>> ../../binutils-gdb/gdb/inferior.h:553:39: error: *((void*)(&
>>> maybe_restore_inferior)+40).scoped_restore_current_inferior::m_saved_inf
>>> may be used uninitialized in this function [-Werror=maybe-uninitialized]
>>> { set_current_inferior (m_saved_inf); }
>>> ^
>>> ../../binutils-gdb/gdb/infrun.c:940:6: note: *((void*)(&
>>> maybe_restore_inferior)+40).scoped_restore_current_inferior::m_saved_inf
>>> was declared here
>>> maybe_restore_inferior;
>>> ^~~~~~~~~~~~~~~~~~~~~~
>>> In file included from ../../binutils-gdb/gdb/inferior.h:46:0,
>>> from ../../binutils-gdb/gdb/infrun.c:26:
>>> ../../binutils-gdb/gdb/progspace.h:274:47: error: *((void*)(&
>>> maybe_restore_inferior)+32).scoped_restore_current_program_space::m_saved_pspace
>>> may be used uninitialized in this function [-Werror=maybe-uninitialized]
>>> { set_current_program_space (m_saved_pspace); }
>>> ^
>>> ../../binutils-gdb/gdb/infrun.c:940:6: note: *((void*)(&
>>> maybe_restore_inferior)+32).scoped_restore_current_program_space::m_saved_pspace
>>> was declared here
>>> maybe_restore_inferior;
>>> ^~~~~~~~~~~~~~~~~~~~~~
>>
>> Fun, looks like gdb::optional related ...
>>
>> Thanks,
>> Pedro Alves
>
> What do you need to reproduce this? GCC 7?
The above is g++ 6.3.1, if I can trust the buildslave description page.
I didn't try that release, but gcc master warns the same way.
And, if I hack the code to use std::optional instead of gdb::optional :
diff --git c/gdb/infrun.c w/gdb/infrun.c
index d0504de..11196ee 100644
--- c/gdb/infrun.c
+++ w/gdb/infrun.c
@@ -910,6 +910,8 @@ private:
scoped_restore_current_inferior m_inferior;
};
+#include <optional>
+
/* Called whenever we notice an exec or exit event, to handle
detaching or resuming a vfork parent. */
@@ -936,9 +938,9 @@ handle_vfork_child_exec_or_exit (int exec)
inf->vfork_parent->pending_detach = 0;
- gdb::optional<scoped_restore_exited_inferior>
+ std::optional<scoped_restore_exited_inferior>
maybe_restore_inferior;
- gdb::optional<scoped_restore_current_pspace_and_thread>
+ std::optional<scoped_restore_current_pspace_and_thread>
maybe_restore_thread;
/* If we're handling a child exit, then inferior_ptid points
and compile with -std=gnu++17, I get the exact same warning again...
src/gdb/infrun.c
In file included from /home/pedro/gdb/mygit/cxx-convertion/src/gdb/infrun.c:26:0:
/home/pedro/gdb/mygit/cxx-convertion/src/gdb/inferior.h: In function ‘void handle_vfork_child_exec_or_exit(int)’:
/home/pedro/gdb/mygit/cxx-convertion/src/gdb/inferior.h:553:26: error: ‘*((void*)(& maybe_restore_inferior)+40).scoped_restore_current_inferior::m_saved_inf’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
{ set_current_inferior (m_saved_inf); }
~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
/home/pedro/gdb/mygit/cxx-convertion/src/gdb/infrun.c:942:6: note: ‘*((void*)(& maybe_restore_inferior)+40).scoped_restore_current_inferior::m_saved_inf’ was declared here
maybe_restore_inferior;
^~~~~~~~~~~~~~~~~~~~~~
In file included from /home/pedro/gdb/mygit/cxx-convertion/src/gdb/inferior.h:46:0,
from /home/pedro/gdb/mygit/cxx-convertion/src/gdb/infrun.c:26:
/home/pedro/gdb/mygit/cxx-convertion/src/gdb/progspace.h:274:31: error: ‘*((void*)(& maybe_restore_inferior)+32).scoped_restore_current_program_space::m_saved_pspace’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
{ set_current_program_space (m_saved_pspace); }
~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
/home/pedro/gdb/mygit/cxx-convertion/src/gdb/infrun.c:942:6: note: ‘*((void*)(& maybe_restore_inferior)+32).scoped_restore_current_program_space::m_saved_pspace’ was declared here
maybe_restore_inferior;
^~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
AFAICS so far, this is a false positive.
Not sure what to do. I wouldn't want to force-memset
the optional's storage to work around it, which would be
a pessimization to quiet a warning. From above, we see that
that wouldn't work when we later start using std::optional.
There's a bug open about this (for boost::optional, but most
probably the exact same):
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78044
Comment #2 makes me think that we should really disable
the warning, or at least make it "-Wno-error=maybe-uninitialized".
I've seen other similar comments around the interwebs when looking
for this warning + optional.
Maybe I could check if the gcc folks plan on doing something to
std::optional to work around this.
Thanks,
Pedro Alves