From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 4DE653844046 for ; Tue, 28 Jul 2020 12:59:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4DE653844046 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark@simark.ca Received: from [10.0.0.11] (173-246-6-90.qc.cable.ebox.net [173.246.6.90]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id D03A61E794; Tue, 28 Jul 2020 08:59:11 -0400 (EDT) Subject: Re: [PATCH][gdb/build] Fix Wmaybe-uninitialized in gdb_optional.h To: Tom de Vries , gdb-patches@sourceware.org References: <20200724124255.GA14763@delia> From: Simon Marchi Message-ID: Date: Tue, 28 Jul 2020 08:59:05 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: <20200724124255.GA14763@delia> Content-Type: text/plain; charset=utf-8 Content-Language: fr Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Jul 2020 12:59:13 -0000 On 2020-07-24 8:42 a.m., Tom de Vries wrote: > Hi, > > When building with CFLAGS/CXXFLAGS="-O2 -g -Wall", we run into: > ... > In file included from src/gdb/exceptions.h:23, > from src/gdb/utils.h:24, > from src/gdb/defs.h:630, > from src/gdb/record-btrace.c:22: > src/gdb/ui-out.h: In function 'void btrace_insn_history(ui_out*, \ > const btrace_thread_info*, const btrace_insn_iterator*, \ > const btrace_insn_iterator*, gdb_disassembly_flags)': > src/gdb/ui-out.h:352:18: warning: \ > 'asm_list.ui_out_emit_type::m_uiout' may be used \ > uninitialized in this function [-Wmaybe-uninitialized] > 352 | m_uiout->end (Type); > | ~~~~~~~~~~~~~^~~~~~ > src/gdb/record-btrace.c:795:35: note: \ > 'asm_list.ui_out_emit_type::m_uiout' was declared here > 795 | gdb::optional asm_list; > | ^~~~~~~~ > ... > > This is reported as PR gcc/80635 - "[8/9/10/11 regression] std::optional and > bogus -Wmaybe-uninitialized warning". > > Silence the warning by using the workaround suggested here ( > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635#c53 ): > ... > union > { > struct { } m_dummy; > T m_item; > + volatile char dont_use; // Silences -Wmaybe-uninitialized warning. > }; > ... > > Build on x86_64-linux. > > Any comments? > > Thanks, > - Tom > > [gdb/build] Fix Wmaybe-uninitialized in gdb_optional.h > > gdbsupport/ChangeLog: > > 2020-07-24 Tom de Vries > > PR build/26281 > * gdb_optional.h (class optional): Add volatile member to union > contaning m_dummy and m_item. > > --- > gdbsupport/gdb_optional.h | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/gdbsupport/gdb_optional.h b/gdbsupport/gdb_optional.h > index 02a87f6ee4..221b4f75b7 100644 > --- a/gdbsupport/gdb_optional.h > +++ b/gdbsupport/gdb_optional.h > @@ -208,6 +208,7 @@ class optional > { > struct { } m_dummy; > T m_item; > + volatile char dont_use; // Silences -Wmaybe-uninitialized warning. > }; > > /* True if the object was ever emplaced. */ > This is fine with me, but I'd use /* */ style comments as usual, and maybe point to the specific gcc PR in the comment, as you did in the other patch. People can always use git blame to find it, but having it right there is handy. Simon