From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id yP4YFz2jAmtW9CsAWB0awg (envelope-from ) for ; Sun, 22 Nov 2026 03:09:33 -0500 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TUOcdFe7; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 2DCBA1E09B; Sun, 22 Nov 2026 03:09:33 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham 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 DE5C01E09B for ; Sun, 22 Nov 2026 03:09:30 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7F0E042A9497 for ; Sun, 22 Nov 2026 08:09:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7F0E042A9497 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TUOcdFe7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id D75BE430AEEA for ; Sun, 22 Nov 2026 08:09:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D75BE430AEEA Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D75BE430AEEA Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795334943; cv=none; b=LvMtQB2zca/BQP6hHnR/oDY1M9BJPmd9zGxyCRc/UUUQECqSESI8hp8uPRNTk0u9mjjwooC2tPDW4WOFvwt3iOLAybMX8KeeEyiRdxaFGz/J2r8rVvr5iSbmDuoY0UyUwbNHBD094TPOy1emdkkjAw4x5Czg6BSPUW6qzGmfWrw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795334943; c=relaxed/simple; bh=4szxAbGleYidwCzBOeA7/0pIa3M5+aLDTyY4Owj+Wg8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=eUUbZhFumJXoAw3Pcc7mwL68Wc+fFPvpAnrYYlAH5tKfiwRwGRUYUSqT33OzLZ/Ji6rdNFtayxX4gHOvXer6Sfx/qryK/2O5h/jmP+QInrtY6rixIPH8fEr8QM63/OBszbco7IhRBEI/8Oa7a+aFXw7BKWOQdCf35BrqezyJCbw= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TUOcdFe7 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D75BE430AEEA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1795334942; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=wA0PDggiI8L2Q6iEJG9HJalx77H4xPToE6raHC0yYsU=; b=TUOcdFe7dexZyNtqbizaDc72bkkTZzYYxhsak0Yal0TH0FEvLq7+YCcuIzYp8G4j281qQq BC9Tlz5PmPlNg0I737z3iqB2QIKP6pA6I25LqMOSs+i8/hJjlFxWAmmgxJwataV3zxyLIg QRhcM0rsXHEJfHNufpPLzpUQJJLKOHo= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-82-eNIA-oHnNcGKj-w9wEAllA-1; Sun, 22 Nov 2026 08:08:59 +0000 X-MC-Unique: eNIA-oHnNcGKj-w9wEAllA-1 X-Mimecast-MFC-AGG-ID: eNIA-oHnNcGKj-w9wEAllA_1795334938 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-490c1867460so1383649f8f.2 for ; Sun, 22 Nov 2026 00:08:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795334938; x=1795939738; h=content-type:mime-version:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=wA0PDggiI8L2Q6iEJG9HJalx77H4xPToE6raHC0yYsU=; b=UmimkK2JxB80Mw3UsQ2Bp1mnV6IXRsRGicv7YmE/IxnJYZl1dcj89ITaW/x2jw2haK yUhpGHBGRnjFwsQWJ9FdM1Pbu7T/1xlWBrg5RTcz1Blun8kzJS6HBwYapPF8yvfDi2gp XDK+CxuBKJMQerM7ieQxejE+y9lCam7AYSG2TRzHdjpGyWNMsJxBkXjxo4+sHOJnNX97 w/qXo9f/qjP4ZmNDU23BhklRIdGYRFLzTGTvSIwJ0SfUjd1aEA3WFkGJInSw6D+xoIkk /sMTmfSOmOf4iOtIYRkyzlKmEJQ8Z7UrkjzyuQRaZsdShtYzOehLlG9iUmKUpxV2HMOM sCYw== X-Forwarded-Encrypted: i=1; AL+hErHbziaDNzG/JubVC7+oVq/0VMgk2hIkeaSPLaYGG5QAZVHcUmIiSz7ZKOchYG8Aimlot53iT4wxx3DsDQ==@sourceware.org X-Gm-Message-State: APuU4Z+xe6HbSb7PfINnhE/Wtq2Pd0igtoIuPBflno0VdI3fTmkwfGuw 6q52veJjIEK3ts8Sl/qkaMQPrwXrHgGU7lZIdphwQYZkE0JGpOStr1UHMookJp3OvrW4WqOS6aM ZXVJ+5x2HndQpYEvgJ2QSBfX6nviz6bh8ajUfWBQdW2rmK344pryVUKcuKO2fWt4= X-Gm-Gg: AZFdTZcsRGIBMoBvSBU54o5uY89wlVYRB39sMlecSIm76s6jovIIBDz7iKJge1Km3nP pZHurWLLTPjAxRNtrATrEM9NKMNQwk8Id1i9Rrh5S2yZOWX+MoK0qB1zt1SCVaqNZlpfL9xZEaU CZyS5I2p25i7a7Enz7gZKG3rguVlvpOUHGgA/D4brI7a0GZpOCZABHBhS/zHfSMklHRpILEtnF8 KaRsb0aZhVVFjGUq6buompxCP58mX2yXWtsIFCSeXZ0Sc9+hl53JBTUjfawdlk/B3dNYZxCO9kJ 2dfHOlBz605efzNb5rzb1F6pV7IObFJEjZ46TpSy8dKhJPoEsWBsBJq4QECmoxKlbJ1/zCuVmza vLmjlsmP3Rp22gEJmtnmRZe8FvIMIhM8HuSW440VD6sKAGjM= X-Received: by 2002:a05:600c:4e0d:b0:4bb:5f07:10d7 with SMTP id 5b1f17b1804b1-4bb8882445cmr166729895e9.26.1795334937986; Sun, 22 Nov 2026 00:08:57 -0800 (PST) X-Received: by 2002:a05:600c:4e0d:b0:4bb:5f07:10d7 with SMTP id 5b1f17b1804b1-4bb8882445cmr166729355e9.26.1795334937498; Sun, 22 Nov 2026 00:08:57 -0800 (PST) Received: from localhost ([83.216.138.189]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb884a3a3dsm228484345e9.10.2026.11.22.00.08.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Nov 2026 00:08:56 -0800 (PST) From: Andrew Burgess To: Tom Tromey , gdb-patches@sourceware.org Cc: Tom Tromey Subject: Re: [PATCH] Make gdb::span handle nullptr like std::span In-Reply-To: <20261122054124.3738131-1-tom@tromey.com> References: <20261122054124.3738131-1-tom@tromey.com> Date: Sun, 22 Nov 2026 08:08:54 +0000 Message-ID: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: NBRFt5MHwsCfAhZHCx9mXyGlPXPkGdH5-snzzxYog4c_1795334938 X-Mimecast-Originator: redhat.com Content-Type: text/plain 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 Tom Tromey writes: > 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 I don't see any benefit of wrapping these in _GLIBCXX_DEBUG. Sure it means we match the std::span behaviour, but all that really means is that we fail to spot undefined behaviour, which isn't a good thing. I'd prefer these were just unwrapped gdb_assert(...) calls. But if you feel strongly about it then I'm not trying to block this fix. I think you should copy the value::contents_for_printing fix to its overload. The patches I had posted also copied the regcache fix (or something like it) to more places (in gdbsupport/common-regcache.*) , you might consider doing the same, but if not I'll post a follow up once this is merged. I think you should just go ahead and merge your patch: Approved-By: Andrew Burgess Thanks, Andrew > + } > > /* 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 -- > 2.49.0