From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 5B1C3385840F for ; Fri, 24 Feb 2023 09:50:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5B1C3385840F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1677232248; 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=2U7RLPogiC6mRl1H/4AAhkFraxKO9e6J72eelzkZZWI=; b=DkBGijXe4TdqYaoVrbBdZ/vT7J/0sV7ExstRe3VIqwNDby3SqvuqXM8DydE995J4Zus4qb n4Ky/bFtimDgXhNKSIBERGvaM8mtLMUuC/EC2Ld/NLMNsKNmWpyYcI7KO16tp5vj7SCfCB h3/ZypWpzm5HY8EEq8gJwPF57SntBw8= Received: from mail-lf1-f72.google.com (mail-lf1-f72.google.com [209.85.167.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-50-GB3GQPQ6N3q4676qIhpbmw-1; Fri, 24 Feb 2023 04:50:46 -0500 X-MC-Unique: GB3GQPQ6N3q4676qIhpbmw-1 Received: by mail-lf1-f72.google.com with SMTP id a11-20020a195f4b000000b004b53d7241f6so3903176lfj.4 for ; Fri, 24 Feb 2023 01:50:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2U7RLPogiC6mRl1H/4AAhkFraxKO9e6J72eelzkZZWI=; b=Y0jsMVn8f82pJAhEpwjvNhX2afd1cEqBC7Ob7bHfqEzPEX/uzk6GD0eqH3GxvdCxLc 2JY1wzEe78VHrJsSOU7oWmXhrG4TMJJ2cVUNWwwVO/EJA2UFMfDT5PKxOd/LNQRE+unH l9xEsctmmOYa+hJGxao/kbK/7+l5BRnAP7d6r2mLs/W3xe7+oKmRUrjHBrh7pg5M+z8H t2lHGBYQRkAzFLRzmNjRygDdV+JWwYX7ppi163WKL9yJzG9X8h/YIPah1FWj68994gug hYE1RRteoIpBotN7iZS1AZCvzk9TokzAAyD47Lzy5BmpZP6MK+LPgGsyxDV6+f+UjITe Qfog== X-Gm-Message-State: AO0yUKWNfA0wCujGk86TBpJN2HDZVKG0G0oe5osCXHlTWnWOOW0tt0dZ 843hqSGN+FJL7kTMVofkEzkLwz2JZktHZs0QPcwcBO0ypiJnh1I5ShQD0Yxh8VMG4vp6broprhf g5nKsoz8OCDfQBA5xQbJ/JbVgADfEKBlui5koSZQ= X-Received: by 2002:ac2:4426:0:b0:4d8:5f47:e4d3 with SMTP id w6-20020ac24426000000b004d85f47e4d3mr4530203lfl.8.1677232245102; Fri, 24 Feb 2023 01:50:45 -0800 (PST) X-Google-Smtp-Source: AK7set9PjMrYVV1moogcJqUhM5FszoveB/ZqnMDAnM67xzDhBAEa71b6Mu7UusFUUuOXxQ0vPgvDvX/N3UMcZG7at00= X-Received: by 2002:ac2:4426:0:b0:4d8:5f47:e4d3 with SMTP id w6-20020ac24426000000b004d85f47e4d3mr4530192lfl.8.1677232244829; Fri, 24 Feb 2023 01:50:44 -0800 (PST) MIME-Version: 1.0 References: <20230223125427.DA402139B5@imap2.suse-dmz.suse.de> In-Reply-To: From: Jonathan Wakely Date: Fri, 24 Feb 2023 09:50:33 +0000 Message-ID: Subject: Re: [PATCH] Avoid default-initializing auto_vec storage To: Jakub Jelinek Cc: Richard Biener , gcc-patches@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-6.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, 24 Feb 2023 at 09:49, Jakub Jelinek wrote: > > Assuming a compiler handles the T m_vecdata[1]; as flexible array member > like (which we need because standard C++ doesn't have flexible array members > nor [0] arrays), I wonder if we instead of the m_auto followed by m_data > trick couldn't make auto_vec have > alignas(vec) unsigned char buf m_data[sizeof (vec) + (N - 1) * sizeof (T)]; > and do a placement new of vec into that m_data during auto_vec > construction. Isn't it then similar to how are flexible array members > normally used in C, where one uses malloc or alloca to allocate storage > for them and the storage can be larger than the structure itself and > flexible array member then can use storage after it? You would still be accessing past the end of the vec::m_vecdata array which is UB.