From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id IutZEK6AAmuplSsAWB0awg (envelope-from ) for ; Sun, 22 Nov 2026 00:42:06 -0500 Authentication-Results: simark.ca; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=Cwf50MP8; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 2D9071E09B; Sun, 22 Nov 2026 00:42:06 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIM_INVALID,DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=no autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (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 D86AE1E09B for ; Sun, 22 Nov 2026 00:42:04 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B5C6C42A7552 for ; Sun, 22 Nov 2026 05:42:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B5C6C42A7552 Authentication-Results: sourceware.org; dkim=fail reason="signature verification failed" (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=Cwf50MP8 Received: from omta036.useast.a.cloudfilter.net (omta036.useast.a.cloudfilter.net [44.202.169.35]) by sourceware.org (Postfix) with ESMTPS id E96B942A755D for ; Sun, 22 Nov 2026 05:41:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E96B942A755D Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E96B942A755D Authentication-Results: sourceware.org; arc=none smtp.remote-ip=44.202.169.35 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795326098; cv=none; b=FgODtZO+giyuDfNB0odPU8a4gNfhOafO4z8XGMrCwCFPMlgJ78eiCFNJlKp2iMtoqK7pFyyyAk+XdUT7l4cRdTxBzyJFKQzS54on5ktNrqa8AApQ0OnuNxpWz6Fuq27254rAKu5yAc+IYTE+9UH2+jKU27ugX7NTQ3/2DnzV0O0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795326098; c=relaxed/simple; bh=BKyVhfL/bMcxqY0RYXmoaXvu5xLPKXcXG66gif2FBSM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=BT1Bxf6Gk4lA/bilR83HDZvF8Nokft/kU/V7cEg/eALRUwpbYAslPlV8RNxGDVG5+L7maQ574K9C8X7s5NExEBJvWyeBDFbV/BEm5NGoXGdE2k1Bb3LDRV9zMSug1ZWTVxH95zkjJhYOwcfbfcJICQ1je2I//z04URlDgQp83Bw= ARC-Authentication-Results: i=1; sourceware.org; dkim=policy (768-bit key, unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=Cwf50MP8 reason="signing key too small" DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E96B942A755D Received: from eig-obgw-6007b.ext.cloudfilter.net ([10.0.30.166]) by cmsmtp with ESMTPS id Ut7sxpKY34vCDV0KXx1rE3; Sun, 22 Nov 2026 05:41:37 +0000 Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTPS id V0KVxUK2m3nNNV0KVxVQYE; Sun, 22 Nov 2026 05:41:35 +0000 X-Authority-Analysis: v=2.4 cv=TuLmhCXh c=1 sm=1 tr=0 ts=6b02808f a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=zJRp6_cAMcgA:10 a=ItBw4LHWJt0A:10 a=8aktfwU0lDuLlaFtup4A:9 a=DCx65vhANUyCzuf5D8fC:22 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Unsubscribe-Post:List-Subscribe:List-Post:List-Owner:List-Archive; bh=uDnj2KTi0sgEYcFvIg0YLZEmBoHIJKqOYXp8iHBlsTY=; b=Cwf50MP8mYhp3hBGgkqjSZMtES tqbNme5taYBbKfrrqC6xtrQ0wD/4p88EoeD2ExmTCAFuoaTunhFEGRUWNkTnwxOGfg/4BHOic11XO WTNO7/+LwaIyBE7F31Q3fg+vW; Received: from 97-122-110-129.hlrn.qwest.net ([97.122.110.129]:38296 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.100.1) (envelope-from ) id 1xV0KU-00000003qSh-49q3; Sat, 21 Nov 2026 22:41:35 -0700 From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Make gdb::span handle nullptr like std::span Date: Sat, 21 Nov 2026 22:41:24 -0700 Message-ID: <20261122054124.3738131-1-tom@tromey.com> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.110.129 X-Source-L: No X-Exim-ID: 1xV0KU-00000003qSh-49q3 X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-110-129.hlrn.qwest.net (localhost.localdomain) [97.122.110.129]:38296 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Org: HG=bhshared;ORG=bluehost; X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-CMAE-Envelope: MS4xfKSmcU5NbvxW/yY5tfIObfYON4FggH/NsI1q8ba0pPntE0ZFnz1og/857Oc9lCvSbj3Ocl3t4QSmkJhzFTgHrUEvkYNdtSHMg8pbfK7etdljMKEJinF7 74AIMuam6ZdfiUNiueJmT4rgmWeQgh0VVomyhxKX3JKKCk75OFvGKkaZocdD9ok5w84/ElZGHp5fpB1t+HvKypKS0BiIUD2nC64= 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 A C++20 std::span can be constructed with nullptr, but only if the length is 0. gdb was violating this rule in a couple of places. This patch fixes two spots and changes gdb::span to have a similar debug-mode assert. I regression tested this (1) with '-std=c++20 -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC', and (2) with an ordinary build but with a version of this patch where the asserts were unconditional. --- gdb/regcache.c | 2 +- gdb/value.c | 6 +++++- gdbsupport/span.h | 12 ++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/gdb/regcache.c b/gdb/regcache.c index 0e7e6a85284..a23c2dd318f 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -1161,7 +1161,7 @@ reg_buffer::raw_supply (int regnum, const void *src) { assert_regnum (regnum); - int size = m_descr->sizeof_register[regnum]; + int size = src == nullptr ? 0 : m_descr->sizeof_register[regnum]; raw_supply (regnum, gdb::make_span ((const gdb_byte *) src, size)); } diff --git a/gdb/value.c b/gdb/value.c index 195f4bb5185..a16cb2a6752 100644 --- a/gdb/value.c +++ b/gdb/value.c @@ -1158,8 +1158,12 @@ value::contents_for_printing () if (m_lazy) fetch_lazy (); + const gdb_byte *contents = m_contents.get (); + if (contents == nullptr) + return {}; + ULONGEST length = enclosing_type ()->length (); - return gdb::make_span (m_contents.get (), length); + return gdb::make_span (contents, length); } gdb::span diff --git a/gdbsupport/span.h b/gdbsupport/span.h index 5288391d2e1..defd38c655e 100644 --- a/gdbsupport/span.h +++ b/gdbsupport/span.h @@ -109,7 +109,11 @@ class span typename = Requires>> constexpr span (U *array, size_t size) noexcept : m_array (array), m_size (size) - {} + { +#if defined(_GLIBCXX_DEBUG) + gdb_assert (m_size != nullptr || m_size == 0); +#endif + } /* Create a span from a range. This is templated on both U an V to allow passing in a mix of 'const T *' and 'T *'. */ @@ -118,7 +122,11 @@ class span typename = Requires>> constexpr span (U *begin, V *end) noexcept : m_array (begin), m_size (end - begin) - {} + { +#if defined(_GLIBCXX_DEBUG) + gdb_assert ((begin == nullptr) == (end == nullptr)); +#endif + } /* Create a span from an array. */ template