From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by sourceware.org (Postfix) with ESMTPS id 9DFC83851C2B for ; Thu, 30 Jul 2020 07:23:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 9DFC83851C2B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tdevries@suse.de X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id E386BAD46; Thu, 30 Jul 2020 07:23:53 +0000 (UTC) Date: Thu, 30 Jul 2020 09:23:39 +0200 From: Tom de Vries To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [committed][gdb/build] Fix Wmaybe-uninitialized in gdb/ui-style.h Message-ID: <20200730072338.GA19062@delia> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, 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: Thu, 30 Jul 2020 07:23:43 -0000 Hi, When building CFLAGS/CXXFLAGS="-O2 -g -Wall" and gcc 4.8.5, we run into: ... src/gdb/cli/cli-style.c:154:42: warning: '*((void*)& +8)' \ may be used uninitialized in this function [-Wmaybe-uninitialized] src/gdb/cli/cli-style.c:154:42: warning: '*((void*)& +9)' \ may be used uninitialized in this function [-Wmaybe-uninitialized] src/gdb/cli/cli-style.c:154:42: warning: '*((void*)& +10)' \ may be used uninitialized in this function [-Wmaybe-uninitialized] ... The root cause is that the data members of class color, nested in struct ui_file_style in gdb/ui-style.h: ... bool m_simple; int m_value; uint8_t m_red, m_green, m_blue; ... are only partially initialized by this constructor: ... color (int c) : m_simple (true), m_value (c) { gdb_assert (c >= -1 && c <= 255); } ... but the default copy constructor will copy all the fields. The member m_simple acts as a discriminant, to indicate which other members are valid: - m_value (with m_simple == true) - m_red, m_green, m_blue (with m_simple == false) So, we don't need storage for both m_value and m_red/m_green/m_blue at the same time. Fix this by wrapping the respective members in a union: ... bool m_simple; union { int m_value; struct { uint8_t m_red, m_green, m_blue; }; }; ... which also fixes the warning. Build and reg-tested on x86_64-linux. Committed to trunk. Thanks, - Tom [gdb/build] Fix Wmaybe-uninitialized in gdb/ui-style.h gdb/ChangeLog: 2020-07-30 Tom de Vries PR build/26320 * ui-style.h (struct ui_file_style::color): Wrap m_value and m_red/m_green/m_blue in a union. --- gdb/ui-style.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/gdb/ui-style.h b/gdb/ui-style.h index 48ab52d5ea..9cb6dda5fc 100644 --- a/gdb/ui-style.h +++ b/gdb/ui-style.h @@ -126,8 +126,14 @@ struct ui_file_style private: bool m_simple; - int m_value; - uint8_t m_red, m_green, m_blue; + union + { + int m_value; + struct + { + uint8_t m_red, m_green, m_blue; + }; + }; }; /* Intensity settings that are available. */