From patchwork Thu Mar 2 20:26:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Marchi X-Patchwork-Id: 65932 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E38333858024 for ; Thu, 2 Mar 2023 20:27:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E38333858024 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1677788844; bh=bay5VzHSuQZyD2FdMZX1xFSUykaQCpFBEIdVS7LCCw8=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=jDI3/RSzQB7el9s7acmJ0E9dB1htkffkvyDh4DKpco265UKIDRLz2UnhBsglYNLq6 Jh/WRNk/N6ciaNUMCAAESbEJLpOMbo63o2Np51/uhP+X604hag86R+L1Bbm7LQiR2J EiRc5KedG00RpDwUyl2MnRuGOwhWwrD19aqw3w8I= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 6FF303858D33 for ; Thu, 2 Mar 2023 20:26:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6FF303858D33 Received: from smarchi-efficios.internal.efficios.com (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 0154C1E0D3; Thu, 2 Mar 2023 15:26:55 -0500 (EST) To: gdb-patches@sourceware.org Cc: Simon Marchi Subject: [PATCH] gdb: fix -Wmaybe-uninitialized warning in value.c Date: Thu, 2 Mar 2023 15:26:55 -0500 Message-Id: <20230302202655.117124-1-simon.marchi@efficios.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-3497.5 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_SOFTFAIL, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Simon Marchi via Gdb-patches From: Simon Marchi Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" Since commit 11470e70ea0d ("gdb: store internalvars in an std::map"), bulding with -O2, with g++ 11.3.0 on Ubuntu 22.04, I see: CXX value.o In constructor ‘internalvar::internalvar(internalvar&&)’, inlined from ‘constexpr std::pair<_T1, _T2>::pair(_U1&&, _U2&&) [with _U1 = const char*&; _U2 = internalvar; typename std::enable_if<(std::_PCC::_MoveConstructiblePair<_U1, _U2>() && std::_PCC::_ImplicitlyMoveConvertiblePair<_U1, _U2>()), bool>::type = true; _T1 = const char*; _T2 = internalvar]’ at /usr/include/c++/11/bits/stl_pair.h:353:35, inlined from ‘constexpr std::pair::type>::__type, typename std::__strip_reference_wrapper::type>::__type> std::make_pair(_T1&&, _T2&&) [with _T1 = const char*&; _T2 = internalvar]’ at /usr/include/c++/11/bits/stl_pair.h:572:72, inlined from ‘internalvar* create_internalvar(const char*)’ at /home/smarchi/src/binutils-gdb/gdb/value.c:1933:52: /home/smarchi/src/binutils-gdb/gdb/value.c:1831:8: warning: ‘.internalvar::u’ may be used uninitialized [-Wmaybe-uninitialized] 1831 | struct internalvar | ^~~~~~~~~~~ /home/smarchi/src/binutils-gdb/gdb/value.c: In function ‘internalvar* create_internalvar(const char*)’: /home/smarchi/src/binutils-gdb/gdb/value.c:1933:76: note: ‘’ declared here 1933 | auto pair = internalvars.emplace (std::make_pair (name, internalvar (name))); | ^ This is because the union field internalvar::u is not initialized when constructing the temporary internalvar object above. That object is then used for move-construction, and the (implicit) move constructor copies the uninitialized bytes of field u over from the temporary object to the new internalvar object. The compiler therefore complains that we use uninitialized bytes. I don't think it's really a problem, because the internalvar object is in the `kind == INTERNALVAR_VOID` state, in which the contents of the union is irrelevant. Still, mute the warning by default-initializing the union. Change-Id: I70c392842f35255f50d8e63f4099cb6685366fb7 Reviewed-By: Tom Tromey --- gdb/value.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gdb/value.c b/gdb/value.c index 10a7ce033fda..7b4df3383048 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1853,7 +1853,7 @@ struct internalvar enum internalvar_kind kind = INTERNALVAR_VOID; - union internalvar_data u; + union internalvar_data u {}; }; /* Use std::map, a sorted container, to make the order of iteration (and