From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by sourceware.org (Postfix) with ESMTPS id 4336D389942B for ; Sun, 11 Dec 2022 13:44:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4336D389942B 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-pj1-x1034.google.com with SMTP id u5so9346545pjy.5 for ; Sun, 11 Dec 2022 05:44:26 -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=hvWmJkjIOpj7n8yWhjQypK39Sx+ONyfj8/W+veTuheE=; b=YHERgS1P9apO2MNJlg0nZsuK5zPidmOj+1Uj518XIhd0Gyc78Q7GAzhsLdBIxxax7N mntVW8/dw/X/8ucIYBJn8vSfOKnOllFjEP67EXSFZv8JazpHynGJfVsFy28E6m2GrUAs wkDQBWNJHeKzPDRJFUVJShEf6WgYOuZHqMvLHOpo/dR5upgUZNN6wXZnGemn+IJlimzt MDKO2SP6RQkhNyEQuYLPLDOhIikxifn7gT3JamKnBHdSuQu8VAdcNzNAUB9xzq3BvznP uC9XYhMlI8ypW5GIMP24811hdpE+1djpqxryZZhldHp1gZwW2xQPcN+6+25lcS2TZgRJ RglA== 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=hvWmJkjIOpj7n8yWhjQypK39Sx+ONyfj8/W+veTuheE=; b=IOuaYkJZkE32xaJblYNMACK1xIq7nAfANzMS2tU8czV3NbhPdzYP7rohHrVm4Xz8x+ HQgRObENiCmX3JzdKV9+fIf9jaleZp/DjioxOqLJny2uajZy/kvfSbKZpYdAbN9a5KA4 vAqM5E5VohINoW/pmXfZcSpV20vzTr/E3bgf/bnQdKI2SKPvtpKsbqecHz9/vd72eQiQ +qvqMcXekaMmiCocch7n9dcSH8Ym2ipTYVPbKFXIZN7I/wC2+Sl8hpEo1DRL99JDNtrJ wkVVuz2t0kwOw8y4cGIZYkE8/8fZKGeQVA+Ok1PpRLQz9s8YsOA/gYzp0XXVp6UNAFb5 5wIw== X-Gm-Message-State: ANoB5pn2iqu90LuCO4TPSlruhVmyp69GqXQ1d4l2lvKkEkD9uYZBOFBz RpT0ZtnrVtUbXMKoW14od5AGlO0JwZAaBp9GfMY= X-Google-Smtp-Source: AA0mqf5NQo2v5cHMqHkmfxn4lzJKfFEDUdOcfyB6S7QlE/F/+h3jYMCNd4IODyTy5/WVwQRvfNBUGAmIqfCQOSVOoZo= X-Received: by 2002:a17:902:b908:b0:189:1ef4:237b with SMTP id bf8-20020a170902b90800b001891ef4237bmr78170573plb.20.1670766265101; Sun, 11 Dec 2022 05:44:25 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Gavin Ray Date: Sun, 11 Dec 2022 08:44:15 -0500 Message-ID: Subject: Re: Bug with GCC's handling of lifetimes of implicit-lifetime types To: Richard Biener Cc: Jonathan Wakely , Andrew Pinski , "gcc@gcc.gnu.org" Content-Type: multipart/alternative; boundary="000000000000bbf02e05ef8d959f" 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: --000000000000bbf02e05ef8d959f Content-Type: text/plain; charset="UTF-8" Whoops, the last line should be pages_span(storage, ...) On Sun, Dec 11, 2022 at 8:38 AM Gavin Ray wrote: > @Richard > > That's some intense code, I appreciate the code-samples and explanation, > thank you =) > > @Jonathan > > Maybe there was some misunderstanding? > I didn't make the connection either but I also don't know that much about > C++ > > It seems like that expression is valid then? Good to know =) > > As a random aside if I may -- what is the difference between placement-new > of pointers in > std::byte storage, and making a std::span over the storage area? > > std::byte storage[PAGE_SIZE * NUM_PAGES]; > > // A) > page* pages = new (storage) page[NUM_PAGES]; > // B) > std::span pages_span(pages, NUM_PAGES); > > > On Sun, Dec 11, 2022 at 8:31 AM Richard Biener > wrote: > >> On Sun, Dec 11, 2022 at 1:02 PM Jonathan Wakely >> wrote: >> > >> > >> > >> > On Sun, 11 Dec 2022, 09:12 Richard Biener, >> wrote: >> >> >> >> On Sat, Dec 10, 2022 at 7:45 PM Andrew Pinski via Gcc >> 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. >> >> >> >> I wouldn't call them "proposals" - basically the C++ language providing >> >> holes into the TBAA system is a misdesign, it will be incredibly >> difficult >> >> to implement this "hole" without sacrifying optimization which means >> >> people will complain endlessly why std::start_lifetime_as isn't a way >> >> to circumvent TBAA without losing optimization. >> > >> > >> > People already make holes in the type system, this just lets them do it >> without UB. If it's not as fast as their UB, that's ok IMHO. >> > >> > >> > >> > But I don't see what start_lifetime_as has to do with the original >> problem anyway. The placement new expression will start lifetimes: >> > >> > page* pages = new (storage) page[NUM_PAGES]; >> > >> > There's no need to mess with the type system here. >> >> That's true, and that should work, not sure what the problem should be >> here. >> >> Richard. >> >> > >> > >> > --000000000000bbf02e05ef8d959f--