From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id 0D7CD384F963 for ; Sat, 10 Dec 2022 21:48:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0D7CD384F963 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-x62c.google.com with SMTP id s7so8372745plk.5 for ; Sat, 10 Dec 2022 13:48:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=9mg76v2EyEgtvER+8ZUhk/4drOCRGU6Uw+2kD8B4YkE=; b=mt9MVwTG16FQG1G3rXM4WkhFfW0dr5a0dt2vpQtcF+TEBm2tXnsY+Z2jnfOxnK/gi8 aaomxthtPtxz/vvrFhCja2qmAarOaM+Hy467OpZY3vxX68voFh6C+SpygzZswbqStXHl 2ql6xGOoAWNu8V/0i4FANJ4LZtVRBAJlahjzNGu/cEpYaoNrvcYA4IlphSjvIz58w2IQ oPtOC0wsqHYGhKMAkIQIqYHPS3HXz2osXc5czG0ftlaNKrNuytBH2DNKCiEmBlQhfxxA 5N+wqKGqhQ/PSj0ZRYRvgu99FgAucmX7FNdacVAhZU9TlGcelFsR3NHEzzz3mn2WJ+tH bQYA== 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=9mg76v2EyEgtvER+8ZUhk/4drOCRGU6Uw+2kD8B4YkE=; b=2W+Zm/TvVUvlEbSOqUGpRplVORhWpXj+sPJhER4ipbTE4Y7ob24170IIPcNpcdULMk BExIOeiZBKtJd2JKKWeIqhMEZx1g8vkqvu+lbTq5KtBMB3tUEENXPPZIalYCDmjqqvbK Lyi8KofoFmd0AaDp88Rbuycll3BTRLugEvFxKBV9lZEVv4gSAoyS5vgbIwmBMYG33nKS /PKIpRO4a9YbJaPscrj8ZSUk8B6/McQO8rbcnjfjBYR2LEfUM3wxjccb+vZBHGVcYxV6 LucjDa8b+APYDCt3L/ECzLL2QZfrXMe0jybzjQS0BrXV8GK5sI+5o0e3MxHbU0O81RGW nTTg== X-Gm-Message-State: ANoB5pnvhhMvKt62FhGtT6QR+W7gMhDafqNdstbEEsLas6JXb+DEBjg3 y1oi5kIz1UqcNGXMmvYrjpu/etGMS5fhxWTx8tw= X-Google-Smtp-Source: AA0mqf4J86ki/Bljm8O4+eQHitko2lMTdHDjJHAESwgrjrOob5TUJJszOGzM139Byw3csXCnqpF6pRQTKHEvA4ZGoFo= X-Received: by 2002:a17:902:e807:b0:189:117c:fcfe with SMTP id u7-20020a170902e80700b00189117cfcfemr79371560plg.124.1670708932571; Sat, 10 Dec 2022 13:48:52 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Gavin Ray Date: Sat, 10 Dec 2022 16:48:42 -0500 Message-ID: Subject: Re: Bug with GCC's handling of lifetimes of implicit-lifetime types To: Andrew Pinski Cc: Jonathan Wakely , gcc@gcc.gnu.org Content-Type: multipart/alternative; boundary="00000000000072f5dc05ef803c7a" X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,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: --00000000000072f5dc05ef803c7a Content-Type: text/plain; charset="UTF-8" Ahh alright, thanks Jonathan & Andrew, appreciate the replies @Jonathan > ... "Without a proper implementation of start_lifetime_as (which GCC doesn't provide yet)" I mailed the author of that proposal yesterday after learning about it (it's very useful!) and they told me as much Had written them to ask about a naive implementation I tried to see if I understood it correctly: - P2590R2: "Explicit lifetime management" (start_lifetime_as) implementation (github.com) > > > > *"Your code copies bytes around. The compiler *might* optimise that away > but I'mnot sure. The idea of start_lifetime_as is that it would compile > down to noinstructions - it would always be a no-op at runtime. My > understanding is thatit cannot be implemented by the user in C++, the > implementation would have to bea "magic" function using compiler > intrinsics."* About the memmove thing, based on a Godbolt link I found from Google -- I think it's relying on UB to initialize storage + lifetime? - Compiler Explorer (godbolt.org) But I don't pretend to understand the technicalities of the above, ha. @Andrew Would you be willing to attempt to explain the linked issue to someone not familiar with the details of C++'s object storage + lifetime model? Seems like an interesting thing but I don't have the technical background/context to understand the full discussion happening there. On Sat, Dec 10, 2022 at 1:44 PM Andrew Pinski wrote: > On Sat, Dec 10, 2022 at 10:36 AM Jonathan Wakely via Gcc > wrote: > > > > On Sat, 10 Dec 2022 at 17:42, Gavin Ray via Gcc wrote: > > > > > > This came up when I was asking around about what the proper way was to: > > > > > > - Allocate aligned storage for a buffer pool/page cache > > > - Then create pointers to "Page" structs inside of the storage memory > area > > > > > > I thought something like this might do: > > > > > > struct buffer_pool > > > { > > > alignas(PAGE_SIZE) std::byte storage[NUM_PAGES * PAGE_SIZE]; > > > page* pages = new (storage) page[NUM_PAGES]; > > > } > > > > > > Someone told me that this was a valid solution but not to do it, > because it > > > wouldn't function properly on GCC > > > They gave this as a reproduction: > > > > > > https://godbolt.org/z/EhzM37Gzh > > > > > > I'm not experienced enough with C++ to grok the connection between this > > > repro and my code, > > > > Me neither. I don't think there is any connection, because I don't > > think the repro shows what they think it shows. > > > > > but I figured > > > I'd post it on the mailing list in case it was useful for others/might > get > > > fixed in the future =) > > > > > > They said it had to do with "handling of lifetimes of implicit-lifetime > > > types" > > > > I don't think that code is a valid implementation of > > start_lifetime_as. Without a proper implementation of > > start_lifetime_as (which GCC doesn't provide yet), GCC does not allow > > you to read the bytes of a float as an int, and doesn't give you the > > bytes of 1.0f, it gives you 0. > > > > https://godbolt.org/z/dvncY9Pea works for GCC. But this has nothing to > > do your code above, as far as I can see. > > See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107115#c10 for what > is going wrong. > Basically GCC does not have a way to express this in the IR currently > and there are proposals there on how to do it. > > Thanks, > Andrew Pinski > --00000000000072f5dc05ef803c7a--