From patchwork Wed Jun 12 14:07:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1946999 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=QSJOJuLg; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) 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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VzpjS2T0Qz1yXv for ; Thu, 13 Jun 2024 01:04:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E5556388264B for ; Wed, 12 Jun 2024 15:04:21 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id E1C583882050 for ; Wed, 12 Jun 2024 15:03:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E1C583882050 Authentication-Results: sourceware.org; dmarc=pass (p=none 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 E1C583882050 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718204636; cv=none; b=HkQKjBPETOLlZ2hoXfM9+Mlz41fVoR2dMzldL6p0IJWCUr70MtWY+GzhSg2mxjzM5/WjqjVV3AH2n1hJBhTy18rw0rnPzW1Ps/lttBRQBvBD3AwmEq84XVTQrDIQzkzFx/WWRm70LkicZ8GBctN+CKL/l3Tc6H917Hj+uJpRvlA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718204636; c=relaxed/simple; bh=MCKmROzzp0sk8UsSUJrvXcTZrrxHGyTeegcEHG444nU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=UrOwu9/0o2nhjlOpt0168xxzVkzq2l0rGPl6ysqvPTUjedwkCiYJNeyDXAfsFa0IZ15b9q7jui7WaXnT3L60yudy1LeBhlNHxXLDjNCYLCaoNnwc04B30kYVxBqUq3bLVjknAg7O9MFiRYzb73tJ4cRDKJ0ARtqqT1PE2gu461U= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718204634; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=TF91hsQw6e74lwwygwU//y4jU7kOE7qP2TDiyEfax5I=; b=QSJOJuLgRCeF3Y87eSI8+QMBkxV7zmlBEPmrUhJW38AA913qhqdYZbYbd6U/CS540zSr72 Ox1Y/s7o+ymz/GfbcSIiDFKaWVY0r2eU3GNL0ELu0r7/HtPiHvFg2fnpJ89UYYgBQns1/4 1v+8ohOvkdro3Wt8nqCenZ4vK8GLeK4= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-186-Ou5mP5SfOlqO2YEIGsgHbA-1; Wed, 12 Jun 2024 11:03:48 -0400 X-MC-Unique: Ou5mP5SfOlqO2YEIGsgHbA-1 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C85721956050; Wed, 12 Jun 2024 15:03:45 +0000 (UTC) Received: from localhost (unknown [10.39.192.128]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0059119560AA; Wed, 12 Jun 2024 15:03:42 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Do not use memset in _Hashtable::clear() Date: Wed, 12 Jun 2024 15:07:45 +0100 Message-ID: <20240612150341.808599-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-linux. Pushed to trunk. -- >8 -- Using memset is incorrect if the __bucket_ptr type is non-trivial, or does not use an all-zero bit pattern for its null value. Replace the three uses of memset with std::fill_n to set the pointers to nullptr. libstdc++-v3/ChangeLog: * include/bits/hashtable.h (_Hashtable::clear): Do not use memset to zero out bucket pointers. (_Hashtable::_M_assign_elements): Likewise. --- libstdc++-v3/include/bits/hashtable.h | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/include/bits/hashtable.h b/libstdc++-v3/include/bits/hashtable.h index 6e78cb7d9c0..983aa909d6c 100644 --- a/libstdc++-v3/include/bits/hashtable.h +++ b/libstdc++-v3/include/bits/hashtable.h @@ -34,6 +34,7 @@ #include #include +#include // fill_n #include // __has_is_transparent_t #if __cplusplus > 201402L # include @@ -1376,8 +1377,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_bucket_count = __ht._M_bucket_count; } else - __builtin_memset(_M_buckets, 0, - _M_bucket_count * sizeof(__node_base_ptr)); + std::fill_n(_M_buckets, _M_bucket_count, nullptr); __try { @@ -1400,8 +1400,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _M_buckets = __former_buckets; _M_bucket_count = __former_bucket_count; } - __builtin_memset(_M_buckets, 0, - _M_bucket_count * sizeof(__node_base_ptr)); + std::fill_n(_M_buckets, _M_bucket_count, nullptr); __throw_exception_again; } } @@ -2582,8 +2581,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION clear() noexcept { this->_M_deallocate_nodes(_M_begin()); - __builtin_memset(_M_buckets, 0, - _M_bucket_count * sizeof(__node_base_ptr)); + std::fill_n(_M_buckets, _M_bucket_count, nullptr); _M_element_count = 0; _M_before_begin._M_nxt = nullptr; }