From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC96CC388F7 for ; Tue, 10 Nov 2020 07:57:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 830432080A for ; Tue, 10 Nov 2020 07:57:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="YOeusAJH" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728323AbgKJH5z (ORCPT ); Tue, 10 Nov 2020 02:57:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56152 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726825AbgKJH5y (ORCPT ); Tue, 10 Nov 2020 02:57:54 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96E05C0613CF for ; Mon, 9 Nov 2020 23:57:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=/OvO5FOl0fJsDal8W8+2BknbSrYQ7RpoUR6AUxHNK38=; b=YOeusAJHDdPEBhp464XNUJ6nw7 bP8Seb5BMOZQKwllocv6tzdr+zOm0dY/mV2gMEd/c7F5sOHp9ALJfwyfD/9LNnguV1WAFUhVZER4K 0nHe9ZgZ5vM5uX9InrI/0UZrwR6DNon4nvAwZS87qtO8uLYLe9vqcEM1qF3PpaWu4+usC0a9lQux0 gnpaU/PcgRX+vWmAg7NjvTK+dz7LEI+WqkLhcXAaZ6+AiJuwvU9VZB/3L6PHwcJ50pTfQEuB59UP+ 6UEM5Ay9VJ+DkS1Lrzb5PkpHuZXzga8QRnH61SOyTzkWvgSl3UlaqT8hLWTzHt/prjBm35nhflpwX sxSvqAUg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcOX9-0004yt-Ir; Tue, 10 Nov 2020 07:57:44 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 1B00D301E02; Tue, 10 Nov 2020 08:57:43 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 065D02C09A80A; Tue, 10 Nov 2020 08:57:43 +0100 (CET) Date: Tue, 10 Nov 2020 08:57:42 +0100 From: Peter Zijlstra To: Nick Desaulniers Cc: Segher Boessenkool , Uros Bizjak , GCC Development , X86 ML , Jakub Jelinek , Andy Lutomirski , linux-toolchains@vger.kernel.org, Christian Borntraeger , Will Deacon , Linus Torvalds , Michael Ellerman Subject: Re: typeof and operands in named address spaces Message-ID: <20201110075742.GT2594@hirez.programming.kicks-ass.net> References: <20201109124713.GP2594@hirez.programming.kicks-ass.net> <20201109193851.GI2672@gate.crashing.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-toolchains@vger.kernel.org On Mon, Nov 09, 2020 at 11:50:15AM -0800, Nick Desaulniers wrote: > On Mon, Nov 9, 2020 at 11:46 AM Segher Boessenkool > wrote: > > > > On Mon, Nov 09, 2020 at 01:47:13PM +0100, Peter Zijlstra wrote: > > > > > > + lots of people and linux-toolchains > > > > > > On Wed, Nov 04, 2020 at 07:31:42PM +0100, Uros Bizjak wrote: > > > > Hello! > > > > > > > > I was looking at the recent linux patch series [1] where segment > > > > qualifiers (named address spaces) were introduced to handle percpu > > > > variables. In the patch [2], the author mentions that: > > > > > > > > --q-- > > > > Unfortunately, gcc does not provide a way to remove segment > > > > qualifiers, which is needed to use typeof() to create local instances > > > > of the per-cpu variable. For this reason, do not use the segment > > > > qualifier for per-cpu variables, and do casting using the segment > > > > qualifier instead. > > > > --/q-- > > > > > > C in general does not provide means to strip qualifiers. > > > > Most ways you can try to use the result are undefined behaviour, even. > > Yes, removing `const` from a `const` declared variable (via cast) then > expecting to use the result is a great way to have clang omit the use > from the final program. This has bitten us in the past getting MIPS > support up and running, and one of the MTK gfx drivers. Stripping const to delcare another variable is useful though. Sure C has sharp edges, esp. if you cast stuff, but since when did that stop anyone ;-) The point is, C++ has these very nice template helpers that can strip qualifiers, I want that too, for much of the same reasons. We might not have templates :-(, but we've become very creative with our pre-processor. Surely our __unqual_scalar_typeof() cries for a better solution.