From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x833.google.com (mail-qt1-x833.google.com [IPv6:2607:f8b0:4864:20::833]) by sourceware.org (Postfix) with ESMTPS id 3EA9E389247C for ; Thu, 17 Dec 2020 15:44:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3EA9E389247C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qt1-x833.google.com with SMTP id 7so20411067qtp.1 for ; Thu, 17 Dec 2020 07:44:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=fj5E4/zuzeaoCokoT3eeKI586oZydmiFXdnyv41wfHQ=; b=Pm5EDrcFIKSvZyFmbbONbUob8wRFRjj04AMOjOBAc2AHVeZP26kTw5J5b1YR4DirBw 092Tlad1kDXVymsVFrUVm8uFun8JYeF81gHZTKrvWE6GuLKtaOM6UvVyqokhftLm6/qR csvA8TymNgaDqFxUDRgZGK9nKQfyqPq+m1fAFItF2J+mO6MmccPYGGNs+0kG3KWwwFCM zoKXoynMh7ecIL2sdshF34xGRa5BVCT7Eyj5PGQyL9QF0oo1MpPjR3OIO6NC1IinN/O/ J+fefqkw9hUdFlx2Am/J19OMzn+6AW+0m7A+pV9tkTzAKoaU8Ks5eyYYSI7EOF5dZ5FT EqZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=fj5E4/zuzeaoCokoT3eeKI586oZydmiFXdnyv41wfHQ=; b=QYBOmCWa6z5ckXiReF0jV6LdEwjXwmAJsIIxL5b79jnYcTTEnsd3pDqhAGseW3XuON vTlVZE9dsfmsN18UZIvsDaEJSe6n8nT69GTf9u7wUTJr5FralvdcMuBxXr3piUNYV5SE rG7XhAlcFf6PbBbicjp52rdj2iIAW3M3NK7Z1DA6YZkyvtJrxOEsRvcbb+99hTK2au0S XEsH5TM/16MOMfGyEVD352Rigt4G+c/P/qcCcaoR2pMzvMg8Uo1zqK+ldhSl/B9gZdkq rfS7Z6/hz+68SO9yZh/82DXbtz2SqvdWRQcbMId6uELfpcseJJPe8RmsksxioH3v/XVE EOxg== X-Gm-Message-State: AOAM533tYmK9DfLBeR7+J9C6DP55YeIMdvL5kKNZiB3u5ayToMZWiCDn sNpXqQ6CkoNtP8YNu1/hV5w= X-Google-Smtp-Source: ABdhPJzz8y2D4AgCyEw5wovTqspIyO7NsylZ6fqtQI3JTQhGJ6BhMsGpjnpaTtK8piS3tQc56J8W7g== X-Received: by 2002:ac8:6d05:: with SMTP id o5mr49845182qtt.6.1608219893504; Thu, 17 Dec 2020 07:44:53 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:e0c4:86e9:6418:b0da? ([2620:10d:c091:480::1:c154]) by smtp.googlemail.com with ESMTPSA id f17sm3217210qtv.68.2020.12.17.07.44.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Dec 2020 07:44:52 -0800 (PST) Sender: Nathan Sidwell Subject: Re: [07/23] Add a class that multiplexes two pointer types To: gcc-patches@gcc.gnu.org References: <878s9wpl6q.fsf@tromey.com> From: Nathan Sidwell Message-ID: <9857f985-3f89-1ebd-c101-b335f3bb5959@acm.org> Date: Thu, 17 Dec 2020 10:44:51 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , X-List-Received-Date: Thu, 17 Dec 2020 15:44:56 -0000 On 12/17/20 10:38 AM, Richard Sandiford via Gcc-patches wrote: > Tom Tromey writes: >>>>>>> "Richard" == Richard Sandiford via Gcc-patches writes: >> >> Richard> +// A class that stores a choice "A or B", where A has type T1 * and B has >> Richard> +// type T2 *. Both T1 and T2 must have an alignment greater than 1, since >> Richard> +// the low bit is used to identify B over A. T1 and T2 can be the same. >> >> It seems like the alignment requirement could be static_assert'd, which >> would make using this class a bit safer. > > Yeah, I wondered about doing that, but in principle there's nothing > to stop people using the class for something like a char*, provided that > the start is suitably aligned. So having gcc_checking_assert is a > compromise: it only provides run-time checking rather than compile-time > checking, but it doesn't place any artificial limits on how the class > can be used. I don;t know whether our optimizers are smart enough (credulous enough?) to know that the low bits of any pointer to an aligned type must be zero, and therefore optimize the assert away in those cases? If they're not something like assert (align (T) > 1 || !(reinterpret_cast (ptr) & 1)) ? -- Nathan Sidwell