From patchwork Tue Mar 19 15:14:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 1913624 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=NjtGp+6x; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4TzZys2rP0z1yWn for ; Wed, 20 Mar 2024 02:15:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 49F04385841F for ; Tue, 19 Mar 2024 15:14:59 +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.129.124]) by sourceware.org (Postfix) with ESMTPS id 490F63858425 for ; Tue, 19 Mar 2024 15:14:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 490F63858425 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 490F63858425 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710861273; cv=none; b=bRRVAU9dlRS9YRglL1oaBPbn5bqiAaBMQKZF1ntlCHQA6TkQbLIeo++75UaW/z5H7+I5EQik6aTlIl41OfHttDbvi+JyCe9IuitxINYhl94NhZycXHwaRzjCmnjDo4I2/ZBDOK6k7ppRqRUIHog7rbXlDo7AlTEbOy4OpAKJJ6s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710861273; c=relaxed/simple; bh=XaxH18fWh7pOvXOpe3Qj+heBGc3PcuYVpOSM048BCUA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=dXyykEKnPk5pxw1khL5Mr6JGwhmJi7vIqmNRu7jWflZ0WVHZr9zJGxekvct3zIqfqauzSAlR+keYnceQGcDrdGwAudybof1dq5PEcBeXv4zjO4EsHeAmPR6fUKjUElWdglqNBT2vLjPPbmA3RONZPsEISjzForvbw+G/KSLNtzs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1710861271; 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=ZgSz0juDyeZuqLPlm2EC7/w+71AO7sAUiMBYeVqaRwc=; b=NjtGp+6xOMQ5RlVOMvQ3/D+riNDGQFcjk6eUxfP3IQmPvkHhn/gwc+e1TiLUyHktze/ELe lD92vDaJVI56MXl/nMQCXnQssqKS0DeP6lVeRl58ZB4+CWqaBXvfxHv50oP42pxBVGvreV zozDgRAFb683NoCtLVJ6eaKxAieBvTw= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-149-0u-GEck3PfuVGu0X5IP2OA-1; Tue, 19 Mar 2024 11:14:30 -0400 X-MC-Unique: 0u-GEck3PfuVGu0X5IP2OA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id 423841C0042C; Tue, 19 Mar 2024 15:14:29 +0000 (UTC) Received: from localhost (unknown [10.42.28.8]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0F0D617A91; Tue, 19 Mar 2024 15:14:28 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Begin lifetime of storage in std::vector [PR114367] Date: Tue, 19 Mar 2024 15:14:06 +0000 Message-ID: <20240319151424.3382794-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 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, SPF_HELO_NONE, SPF_NONE, 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: 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. Backport to gcc-13 to follow. -- >8 -- This doesn't cause a problem with GCC, but Clang correctly diagnoses a bug in the code. The objects in the allocated storage need to begin their lifetime before we start using them. This change uses the allocator's construct function instead of using std::construct_at directly, in order to support fancy pointers. libstdc++-v3/ChangeLog: PR libstdc++/114367 * include/bits/stl_bvector.h (_M_allocate): Use allocator's construct function to begin lifetime of words. --- libstdc++-v3/include/bits/stl_bvector.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/include/bits/stl_bvector.h b/libstdc++-v3/include/bits/stl_bvector.h index 2c8b892b07a..a3343d95b36 100644 --- a/libstdc++-v3/include/bits/stl_bvector.h +++ b/libstdc++-v3/include/bits/stl_bvector.h @@ -674,13 +674,13 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _M_allocate(size_t __n) { _Bit_pointer __p = _Bit_alloc_traits::allocate(_M_impl, _S_nword(__n)); -#if __cpp_lib_is_constant_evaluated +#if __cpp_lib_is_constant_evaluated && __cpp_constexpr_dynamic_alloc if (std::is_constant_evaluated()) - { - __n = _S_nword(__n); - for (size_t __i = 0; __i < __n; ++__i) - __p[__i] = 0ul; - } + { + __n = _S_nword(__n); + for (size_t __i = 0; __i < __n; ++__i) + std::construct_at(std::to_address(__p) + __i); + } #endif return __p; }