From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id EFDDE38493D6 for ; Sat, 10 Dec 2022 18:44:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EFDDE38493D6 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-x633.google.com with SMTP id jl24so8120695plb.8 for ; Sat, 10 Dec 2022 10:44:07 -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=7G5S9AfIGMVMrM5edE5ndO3Y9j5L+EHOADsHDzzlwcw=; b=ZFGYQkPSx4KLllE/z4EmzS25du4WB4OgqWW+Ry+pFTy5o6QTHOJ1u4MfRTm2TuWwp3 xN0eDDE4Vy5HWgQuAqgIsuMHxF8MfViPrW4OC9YbqNgIpc8m0lV7RsUZCO2BfQO09ijN FFGeLaUZncXk90IUjxSveVevrZtEL/4yP7QwYD3azx9f1Xi5H6QFf0kV3NFqkOsuK4tG rawyjKHR/jX4Og18zzS5F+kTiBcEAUZQtkYZnEI+SxSH8hSY2fojD3xEkFM4m1A1DD4r g8lOlRcdFVETe+KzgJ+qQt+wbc4QmAX3q9jVCE8LVFMSq/C8JHoNroQzye3W8I7dslJ9 P8SQ== 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=7G5S9AfIGMVMrM5edE5ndO3Y9j5L+EHOADsHDzzlwcw=; b=jxrP1By+AmZemMQn2lbOPIHb7+ZMbqnM8MfxlllOhEya9sbLi5VxaVnKV4kXYIAkoN SBfm7g2sp8cdP3wHyu/2PcmSgX1JKIZHWWouspbDBcVXwS88Hg78LMeqZQxwSPYDvRKJ d7J5tlYemcwx7WTSvY63cblTI86t7FydS9zAcXv/H1hqwOwwe+rDk8Wk/zA3uw8stlBT opbHIuwVj+3pCkTnhJ75QWahWiJc3WZFu6AC1Q9rRZBNBMyAfV4/CZ9N8YP2kM4/yWk3 TyMZ5MFYvJssz9X+S9fpjkIFM3RxATpjCDxFDHI2mLepH/tgpyYgvbOQ52B9TSul8NX4 WSdQ== X-Gm-Message-State: ANoB5pmuOMkMd2ta6vxYsdennqTdtlGJV03Wn97s1dHKmeOBhdAwywtO EpXf2dn1q201BLrbZhHus7WlxJHrAcbLv1DlbzE= X-Google-Smtp-Source: AA0mqf56gxy8MuVh7V2ylCYQ2gD8W5xWv+Sx1UX7hczbayv886IWaR70u/b9gG2EOhhRZq43UW5702JHM3PREPRr19c= X-Received: by 2002:a17:90b:3c8a:b0:219:f8ee:c7fc with SMTP id pv10-20020a17090b3c8a00b00219f8eec7fcmr14207080pjb.163.1670697846862; Sat, 10 Dec 2022 10:44:06 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Andrew Pinski Date: Sat, 10 Dec 2022 10:43:55 -0800 Message-ID: Subject: Re: Bug with GCC's handling of lifetimes of implicit-lifetime types To: Jonathan Wakely Cc: Gavin Ray , gcc@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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: 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