From patchwork Fri Aug 26 16:38:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 790 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp315412wro; Fri, 26 Aug 2022 09:39:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR6YGa6a9MWpNzvtxi7Mm9lOmsj71ENsZuReIE44yelN/05cFq9HntNLsmjBIOP/dkw7AfxO X-Received: by 2002:a17:907:2708:b0:73d:5a17:a48d with SMTP id w8-20020a170907270800b0073d5a17a48dmr5875899ejk.35.1661531964100; Fri, 26 Aug 2022 09:39:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661531964; cv=none; d=google.com; s=arc-20160816; b=y/nZUJxUUPkrti87HM4Gr5hC0c39Aj+L+MmmVfeuMjwz/oK3fYwnrilokV7d2OyTz2 sKFD06nGKg/a/Ko+2rLPg2kw3ltzbZsoJAZ2NSvlykelfLtId5xkXvE6DcR2k9U3FRv6 VvLoT0crcF1Kb2rxD34ejsKvVLpAYIJV5pcoSGVY5OM0JRq3mc4M/P7DmW0JkZyVtULM eo4PcpH7jXZ9xaX7VwNgs95XZ4qeLPXehlbKnD4VzaCg/uHKhXkHUr5bv3w3+VPvGLFO XZIAr8SKBcKP/8/4kBPh+QIqD6EG8+SwFzOp2Bh60TTFLfeI+MzMAyDFjwWxRgjtmdlO NiUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mime-version:message-id:date :user-agent:subject:to:from:dkim-signature:dkim-signature :dmarc-filter:delivered-to; bh=BAzBpaBXTdHxPO/xloCAAdw7KVJWg5vdVhqJ04JHZPA=; b=loz4DZdgRnmJN9Wnd1UDq0vFt3BSm62GYlmKcK6AXBXDXnpz4+n3HZ/r4Yl0+Oc4Ds y394ZQxfeNVy2IJLGTcDSroSyy7EmzE4bkSKNeJsDfKZ63Si7jlDMDtNERbth7rgzlCr oqPXI5j2WsMPHCLpyJ2vdETPVAlX6SNoCm8T/pSpDSSN3WjtbwYVVMorr+QkliIUGPGB pddkhpR1KG7ObA8jrWWF6rzO0jUk//l/FCl7umgIgX7Uqu5VV17qANMKNIPUrohbTyCP HFeBWU3oS2wlKOi+re5WwCAjdsLORm/UnmE4UDai9KPEpFqd/p1IGBvJtVpWsYAvApAk zkSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@suse.cz header.s=susede2_rsa header.b=JXLqR17P; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=t3MbTCq3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id e6-20020a17090658c600b00730936657d1si1627337ejs.552.2022.08.26.09.39.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Aug 2022 09:39:24 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=fail header.i=@suse.cz header.s=susede2_rsa header.b=JXLqR17P; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=t3MbTCq3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5A8CA38515E9 for ; Fri, 26 Aug 2022 16:39:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id BCBE138515FD for ; Fri, 26 Aug 2022 16:38:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BCBE138515FD Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id AB96A1F91D; Fri, 26 Aug 2022 16:38:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1661531927; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=BAzBpaBXTdHxPO/xloCAAdw7KVJWg5vdVhqJ04JHZPA=; b=JXLqR17PzNDq5LSmUIFBx1N6df4D+NyHZYZyjFbJR8zyKpBw4u8wO6tRuQ9e8dX1JkHa0D YJGAM3kQRBLWWy4xgUi/YaGpWaNW+ChaoHKVzXOWiMKl5karICL3zBin6opSoegVCNkGW9 yNaIVP4hnk+2Vl98bnm7GuXfRQXOUb8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1661531927; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=BAzBpaBXTdHxPO/xloCAAdw7KVJWg5vdVhqJ04JHZPA=; b=t3MbTCq3etJSf9sG7taqiWtHqfJCbPn5fIPbJcO6IvYMZpElxqUB6nyaSd07No6ULLQ1yw wJlw6CHmQI3DEVAQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9DACB13421; Fri, 26 Aug 2022 16:38:47 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id b1FzJhf3CGMtdwAAMHmgww (envelope-from ); Fri, 26 Aug 2022 16:38:47 +0000 From: Martin Jambor To: GCC Patches Subject: [PATCH 1/2] vec: Add array_slice constructors from non-const and gc vectors User-Agent: Notmuch/0.35 (https://notmuchmail.org) Emacs/28.1 (x86_64-suse-linux-gnu) Date: Fri, 26 Aug 2022 18:38:47 +0200 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Sandiford , Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742242540590713059?= X-GMAIL-MSGID: =?utf-8?q?1742242540590713059?= Hi, This patch adds constructors of array_slice that are required to create them from non-const (heap or auto) vectors or from GC vectors. The use of non-const array_slices is somewhat limited, as creating one from const vec still leads to array_slice, so I eventually also only resorted to having read-only array_slices. But I do need the constructor from the gc vector. Bootstrapped and tested along code that actually uses it on x86_64-linux. OK for trunk? Thanks, Martin gcc/ChangeLog: 2022-08-08 Martin Jambor * vec.h (array_slice): Add constructors for non-const reference to heap vector and pointers to heap vectors. --- gcc/vec.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gcc/vec.h b/gcc/vec.h index eed075addc9..b0477e1044c 100644 --- a/gcc/vec.h +++ b/gcc/vec.h @@ -2264,6 +2264,18 @@ public: array_slice (const vec &v) : m_base (v.address ()), m_size (v.length ()) {} + template + array_slice (vec &v) + : m_base (v.address ()), m_size (v.length ()) {} + + template + array_slice (const vec *v) + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} + + template + array_slice (vec *v) + : m_base (v ? v->address () : nullptr), m_size (v ? v->length () : 0) {} + iterator begin () { return m_base; } iterator end () { return m_base + m_size; }