From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id fp0uJ8SmcWYQ6zwAWB0awg (envelope-from ) for ; Tue, 18 Jun 2024 11:24:52 -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=JICl8Jlj; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=waSxReA0; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=JICl8Jlj; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=waSxReA0; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 91F9B1E0C1; Tue, 18 Jun 2024 11:24:52 -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 5FFBD1E030 for ; Tue, 18 Jun 2024 11:24:50 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CC0F33882ACB for ; Tue, 18 Jun 2024 15:24:49 +0000 (GMT) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by sourceware.org (Postfix) with ESMTPS id 6AEB63882AC6 for ; Tue, 18 Jun 2024 15:24:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6AEB63882AC6 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 6AEB63882AC6 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=1718724269; cv=none; b=jUsFPwuw2xAaURHmb3CaD0gGZzF6BiCeYITWCcGqKKocxeRHQUHwdmMlp08i0/bJxVIvjs0BgnQHZhwstl0wS9Ag2ZRw6OeNokm9238t/CqSbfyJU/2pA+fLPlHRTscpGGpwNd1EXPIcosdKCROtTtNh320raw1iN1sLlvQXrVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718724269; c=relaxed/simple; bh=ykX8MEtyY2YhCMwwY3chWE/eO4yudFhhx2wVYXarGWo=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature: Message-ID:Date:MIME-Version:Subject:From:To; b=jPQAn6oTlo/pQ3uL3KkNS17cqQaEcKIlZ7VfvlP3nseJCZn7XhCbGoSvvNqktMxqzkhI1bkNjFzG5cKk/fYaL1YS/dC2rIYEdSQCoH9DJqRmi1ph9FOX53oDwAD0nCN4kXdEQTztWJqres+9M9z6Ln9wi/xtTJCpOfQzISwk62Q= 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 6FF192199A; Tue, 18 Jun 2024 15:24:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718724266; 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=lJLtQj0e1CDUnUScOGZYmI6ysfzdECZey7jeAfR5QuI=; b=JICl8JljHckemiCe057wvRuxOPQtCGkMz8jpqe+KFf9ZiBRl2l6HK7PAR/MstIKKjPkiQZ ZhPpzvf+V7D9HExS41GDSxqklZ93a9u8pXFut1TC1di4HWoHy2g41+QYq0CfbIMpteeny2 AMjZAz/fgpB8zyNNFwkbWcEC8j9aljM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718724266; 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=lJLtQj0e1CDUnUScOGZYmI6ysfzdECZey7jeAfR5QuI=; b=waSxReA035YACt88QNq+drnW+G6lOYXUeKiqwnOaK7emtBDFatxRd2f/MTzIfxBhMj9sfg +lWRof6JL2vR3IAw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1718724266; 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=lJLtQj0e1CDUnUScOGZYmI6ysfzdECZey7jeAfR5QuI=; b=JICl8JljHckemiCe057wvRuxOPQtCGkMz8jpqe+KFf9ZiBRl2l6HK7PAR/MstIKKjPkiQZ ZhPpzvf+V7D9HExS41GDSxqklZ93a9u8pXFut1TC1di4HWoHy2g41+QYq0CfbIMpteeny2 AMjZAz/fgpB8zyNNFwkbWcEC8j9aljM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1718724266; 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=lJLtQj0e1CDUnUScOGZYmI6ysfzdECZey7jeAfR5QuI=; b=waSxReA035YACt88QNq+drnW+G6lOYXUeKiqwnOaK7emtBDFatxRd2f/MTzIfxBhMj9sfg +lWRof6JL2vR3IAw== 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 4C0AF1369F; Tue, 18 Jun 2024 15:24:26 +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 BiL+EKqmcWagCgAAD6G6ig (envelope-from ); Tue, 18 Jun 2024 15:24:26 +0000 Message-ID: <0d8472bf-6074-4417-87e7-5091bb5fc957@suse.de> Date: Tue, 18 Jun 2024 17:25:22 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] gdb/python/python-internal.h: avoid uninitialized constexpr From: Tom de Vries To: Lancelot SIX , gdb-patches@sourceware.org Cc: tom@tromey.com References: <20240618090952.537478-1-lancelot.six@amd.com> <0e8d0e8b-d03c-43fe-a2ac-b26743b331b9@suse.de> Content-Language: en-US In-Reply-To: <0e8d0e8b-d03c-43fe-a2ac-b26743b331b9@suse.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Score: -4.29 X-Spam-Level: X-Spamd-Result: default: False [-4.29 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-0.999]; 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)[imap1.dmz-prg2.suse.org:helo,suse.de:email] X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, BODY_8BITS, 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 15:00, Tom de Vries wrote: > 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 > FWIW, I also did a build-with-clang and test run, and only see the usual suspects + clang-build specific PR31237. 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 >