From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) by sourceware.org (Postfix) with ESMTPS id 99905398680D for ; Tue, 10 Nov 2020 20:11:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 99905398680D 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=merlin.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=OEdejAq9JyTldwtkkTwVWnsgfoK09UjFDo7aHSBmnzk=; b=djPwDpKGHpe/EJ/vJg8Wk6it8A dluzWIRLQXv4s44+2rsP1Qv71BFnSwqvs8hj/aPucnPBccUF5p33Fk349E9cXdD7d9/8s+ImbD7Tn z5K2zeoXE5vgRgQv42omih4BuKYOwH7UDaufipCqry8pyDWNYvze1kJTaGDF6K7Xwzj9Em4lTsR6X +jIIlXpTXwCHUGRvcLKPwV6lvn4PTJsigonwb45dOKX/VaFq2HkRDa0E8YA8DJBCM1vxI/By9kBtC 3gk507sMs6SNQAF97HkuSkdw2yCGdZjLSLvgfTGyEuuILO2U0fnA+x8Rqc5SYygK8QDVDGbXxfgvI RWwqiLLg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcZyy-000592-S7; Tue, 10 Nov 2020 20:11:13 +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 62942301324; Tue, 10 Nov 2020 21:11:08 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 41FB1203DACA7; Tue, 10 Nov 2020 21:11:08 +0100 (CET) Date: Tue, 10 Nov 2020 21:11:08 +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: <20201110201108.GQ2611@hirez.programming.kicks-ass.net> References: <20201109124713.GP2594@hirez.programming.kicks-ass.net> <20201109193851.GI2672@gate.crashing.org> <20201110075742.GT2594@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, 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 20:11:21 -0000 On Tue, Nov 10, 2020 at 10:42:58AM -0800, Nick Desaulniers wrote: > When I think of qualifiers, I think of const and volatile. I'm not > sure why the first post I'm cc'ed on talks about "segment" qualifiers. > Maybe it's in reference to a variable attribute that the kernel > defines? Looking at Clang's Qualifier class, I see const, volatile, > restrict (ah, right), some Objective-C stuff, and address space > (TR18037 is referenced, I haven't looked up what that is) though maybe > "segment" pseudo qualifiers the kernel defines expand to address space > variable attributes? Right, x86 Named Address Space: https://gcc.gnu.org/onlinedocs/gcc-10.2.0/gcc/Named-Address-Spaces.html#Named-Address-Spaces Also, Google found me this: https://reviews.llvm.org/D64676 The basic problem seems to be they act exactly like qualifiers in that typeof() preserves them, so if you have: ( and now I realize the parent isn't Cc'd to LKML, find here: https://gcc.gnu.org/pipermail/gcc/2020-November/234119.html ) > --cut here-- > #define foo(_var) \ > ({ \ > typeof(_var) tmp__; \ > asm ("mov %1, %0" : "=r"(tmp__) : "m"(_var)); \ > tmp__; \ > }) > > __seg_fs int x; > > int test (void) > { > int y; > > y = foo (x); > return y; > } > --cut here-- > when compiled with -O2 for x86 target, the compiler reports: > > pcpu.c: In function ‘test’: > pcpu.c:14:3: error: ‘__seg_fs’ specified for auto variable ‘tmp__’ > Maybe stripping all qualifiers is fine since you can add them back in > if necessary? So far that seems sufficient. Although the Devil's advocate in me is trying to construct a case where we need to preserve const but strip volatile and that's then means we need to detect if the original has const or not, because unconditionally adding it will be wrong.