From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id DCR6L82EcWaTtTwAWB0awg (envelope-from ) for ; Tue, 18 Jun 2024 08:59:57 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ukS4ucGu; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=JcPn5/Gp; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=ukS4ucGu; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=JcPn5/Gp; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id B358D1E0C1; Tue, 18 Jun 2024 08:59:57 -0400 (EDT) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 3E7251E030 for ; Tue, 18 Jun 2024 08:59:55 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 75F263882AD0 for ; Tue, 18 Jun 2024 12:59:54 +0000 (GMT) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 68A783882AC6 for ; Tue, 18 Jun 2024 12:59:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 68A783882AC6 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 68A783882AC6 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718715573; cv=none; b=u8wJpY9bjZpTga/injamt39u4tSNn3UH3r58gvmXXKWCC+81p4Xly1OONNaN5jfBQyR+jbolsZFTQFH70LQ/Fep1hBmLLW+mrf+mzXk9/VOoHK4QU5ri2u0m3uiW2T3b0pXSzMXGMJfS9V9uE+RkJ7oyqhXuBEs03O6jguUII+Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718715573; c=relaxed/simple; bh=HXQZbpXtyjmFC/sls9qNrHTCDbBqC9UEzg6wl2WNTYQ=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:To:From; b=OzX5fcRfcpIhCe5lmeN4e6SACnfpNzMBWeDPFXzBBTu9ClFi4xoY9BNyeLwiWqv7wE0h2cqLL9N1j+PtwF9dZpDBoZGGgkOC0u2w5WNmdpxzuve44+r2S43Wo1f45JLA7SzX2uj0lZUemww7EPJI/ljrzcFu2ebG9lMExxTofaA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 650A4219D3; Tue, 18 Jun 2024 12:59:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718715570; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qrz8ianQ5EdSOSCcdz51ZhRUHgaB6g3YXaMrqT5CW9k=; b=ukS4ucGuj0BRCxim1L+yz/67/HlEE/1ElvdtCHDCYhM+iU6mPcZV4M01VXNCmolphkxohK LDyU18rCL4TMxmSUW4bboRcVctNZrpAqiMr3xnPGZNXPIcF4J23N40DbvNy2lOR/G2UChy VT5ioXUSZERTXdnJLvLYPOim58ChVU4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718715570; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qrz8ianQ5EdSOSCcdz51ZhRUHgaB6g3YXaMrqT5CW9k=; b=JcPn5/Gpu4FRAX4UwGv44zKYTlk/QiFXRZFkYdneYtX0ldjIkB5flD0OGw6ZeC5dGoR15F 2wB028ywYxwMyOAw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718715570; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qrz8ianQ5EdSOSCcdz51ZhRUHgaB6g3YXaMrqT5CW9k=; b=ukS4ucGuj0BRCxim1L+yz/67/HlEE/1ElvdtCHDCYhM+iU6mPcZV4M01VXNCmolphkxohK LDyU18rCL4TMxmSUW4bboRcVctNZrpAqiMr3xnPGZNXPIcF4J23N40DbvNy2lOR/G2UChy VT5ioXUSZERTXdnJLvLYPOim58ChVU4= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718715570; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qrz8ianQ5EdSOSCcdz51ZhRUHgaB6g3YXaMrqT5CW9k=; b=JcPn5/Gpu4FRAX4UwGv44zKYTlk/QiFXRZFkYdneYtX0ldjIkB5flD0OGw6ZeC5dGoR15F 2wB028ywYxwMyOAw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 4636B1369F; Tue, 18 Jun 2024 12:59:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 5hG1D7KEcWZ4XAAAD6G6ig (envelope-from ); Tue, 18 Jun 2024 12:59:30 +0000 Message-ID: <0e8d0e8b-d03c-43fe-a2ac-b26743b331b9@suse.de> Date: Tue, 18 Jun 2024 15:00:26 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] gdb/python/python-internal.h: avoid uninitialized constexpr To: Lancelot SIX , gdb-patches@sourceware.org Cc: tom@tromey.com References: <20240618090952.537478-1-lancelot.six@amd.com> Content-Language: en-US From: Tom de Vries In-Reply-To: <20240618090952.537478-1-lancelot.six@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spamd-Result: default: False [-4.27 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.18)[-0.915]; MIME_GOOD(-0.10)[text/plain]; XM_UA_NO_VERSION(0.01)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; TO_DN_SOME(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; ARC_NA(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,imap1.dmz-prg2.suse.org:helo] X-Spam-Score: -4.27 X-Spam-Level: X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org On 6/18/24 11:09, Lancelot SIX wrote: > The following recent change introduced a regression when building using > clang++: > > commit 764af878259768bb70c65bdf3f3285c2d6409bbd > Date: Wed Jun 12 18:58:49 2024 +0200 > > [gdb/python] Add typesafe wrapper around PyObject_CallMethod > > The error message is: > > ../../gdb/python/python-internal.h:151:16: error: default initialization of an object of const type 'const char' > constexpr char gdbpy_method_format; > ^ > = '\0' > CXX python/py-block.o > 1 error generated. > make[2]: *** [Makefile:1959: python/py-arch.o] Error 1 > make[2]: *** Waiting for unfinished jobs.... > In file included from ../../gdb/python/py-auto-load.c:25: > ../../gdb/python/python-internal.h:151:16: error: default initialization of an object of const type 'const char' > constexpr char gdbpy_method_format; > ^ > = '\0' > 1 error generated. > make[2]: *** [Makefile:1959: python/py-auto-load.o] Error 1 > In file included from ../../gdb/python/py-block.c:23: > ../../gdb/python/python-internal.h:151:16: error: default initialization of an object of const type 'const char' > constexpr char gdbpy_method_format; > ^ > = '\0' > 1 error generated. > > This patch fixes this by changing gdbpy_method_format to be a templated > struct, and only have its specializations define the static constexpr > member "format". This way, we avoid having an uninitialized constexpr > expression, regardless of it being instantiated or not. > Hi Lancelot, thanks for looking into this. This seems to have been my doing, since I dropped the " = '\0'" bit. I can reproduce the problem. I also tried adding back the dropped bit, and saw that it fixes the compilation error. However, that also brings back the problem I was trying to solve: doing this: ... - gdbpy_ref<> result = gdbpy_call_method (m_window, "close"); + gdbpy_ref<> result = gdbpy_call_method (m_window, "close", 1.0); ... compiles, using '\0' as format specificier for double, and we only run into trouble a runtime. The patch you propose both: - fixes the build with clang, and - gives a compile time error for the unsupported format specifier case. So, LGTM. Reviewed-By: Tom de Vries Thanks, - Tom > Change-Id: I5bec241144f13500ef78daea30f00d01e373692d > --- > gdb/python/python-internal.h | 24 ++++++++++++++++++------ > 1 file changed, 18 insertions(+), 6 deletions(-) > > diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h > index f4c35babe46..fec0010a444 100644 > --- a/gdb/python/python-internal.h > +++ b/gdb/python/python-internal.h > @@ -148,19 +148,31 @@ typedef long Py_hash_t; > /* A template variable holding the format character (as for > Py_BuildValue) for a given type. */ > template > -constexpr char gdbpy_method_format; > +struct gdbpy_method_format {}; > > template<> > -constexpr char gdbpy_method_format = GDB_PY_LL_ARG[0]; > +struct gdbpy_method_format > +{ > + static constexpr char format = GDB_PY_LL_ARG[0]; > +}; > > template<> > -constexpr char gdbpy_method_format = GDB_PY_LLU_ARG[0]; > +struct gdbpy_method_format > +{ > + static constexpr char format = GDB_PY_LLU_ARG[0]; > +}; > > template<> > -constexpr char gdbpy_method_format = 'i'; > +struct gdbpy_method_format > +{ > + static constexpr char format = 'i'; > +}; > > template<> > -constexpr char gdbpy_method_format = 'I'; > +struct gdbpy_method_format > +{ > + static constexpr char format = 'I'; > +}; > > /* A helper function to compute the PyObject_CallMethod / > Py_BuildValue format given the argument types. */ > @@ -169,7 +181,7 @@ template > constexpr std::array > gdbpy_make_fmt () > { > - return { gdbpy_method_format..., '\0' }; > + return { gdbpy_method_format::format..., '\0' }; > } > > /* Typesafe wrapper around PyObject_CallMethod. > > base-commit: 0915235d341841ac7f13bd3136991c19b4a6746b