From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by sourceware.org (Postfix) with ESMTPS id 7BFBB3857C46 for ; Tue, 10 Nov 2020 07:57:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7BFBB3857C46 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: sourceware.org; spf=none smtp.mailfrom=peterz@infradead.org 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: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham 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@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Nov 2020 07:57:50 -0000 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.