Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5124624pxj; Wed, 9 Jun 2021 09:39:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxqbfKQL77QrCQB5DdTPI/tbQ3vOajVO8g10dpEtnqCRjELXD6Hgyy7tbzGv2GmhKh9ejxJ X-Received: by 2002:a17:906:f6cb:: with SMTP id jo11mr720504ejb.439.1623256794466; Wed, 09 Jun 2021 09:39:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623256794; cv=none; d=google.com; s=arc-20160816; b=fZTBG/77bkyr7JaGRsVXpZ7WjnmdjquKBlOCEC4IQrpOF9RG45tB8ltYZ+laHGXmwl sxMxj1Y+A4u2FC05WGm2pLUYNeEG29QmehyqZoRMNHE4LMdZhFMSRwNiUALijGPhm1Dz e08PLViGoZwb5VCq+Ej3y5dVhh/YbcvcsGGIhMJ9eiTOVFMT+xlcuASMBNGMcrf8nLkD Z5hja3cerFhOlejZrL3Hbd6tZSLodVwbjWikkmY0rXo2eJKKnagPD4m3CtgbcqHA17qr aw6u7e6mfQ3NkAyBWFZDiFahApykMB/7BjZ889mtKCymi8w3LtLHCdhINYuInY9yJGSp vn3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=qRuQ1mrwTnCrlmtDiCJXdi4p2uv0t05mrbfotbHVxP4=; b=pj4t98FNvgPmuYsIKXylNnBMiyOorewQ1gutnwMchc+RZl0P0jXgkwArSQ+W2um/TE M2txiAeoBT5pPxhCmpNN8OM7b9kAdAVIUTY7RsuEEeUxmhMx0qUeOp0bL0Rep9NACVhS A9vqjsBU+9p3BW8jKEA1FmJyQEHJS081i9MAbX3WrqTucFVaWItXvAAfWJ9RhvvAJFZv M1ZXGBwNuX7sV5bjx24HOY8Jy9Qepjn7X9lAZUyemGCe/q2fBos4a4QEXZiXh8LK/Vr+ UDcA7fBWBK4FK6cKo/+33Z1fAE0geSCKeo/2zoc9XSPq2UT/QjOcCaG7yvGs9Pe8BkQs Iw4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Syg/ICcH"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c17si193099ejc.579.2021.06.09.09.39.30; Wed, 09 Jun 2021 09:39:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b="Syg/ICcH"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230222AbhFIQQX (ORCPT + 99 others); Wed, 9 Jun 2021 12:16:23 -0400 Received: from mail-oi1-f180.google.com ([209.85.167.180]:44571 "EHLO mail-oi1-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231251AbhFIQQX (ORCPT ); Wed, 9 Jun 2021 12:16:23 -0400 Received: by mail-oi1-f180.google.com with SMTP id a26so4892407oie.11 for ; Wed, 09 Jun 2021 09:14:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=qRuQ1mrwTnCrlmtDiCJXdi4p2uv0t05mrbfotbHVxP4=; b=Syg/ICcHnYjw6rdWoTK+LQM5/1dcgL/nGSedZh5kB+3YjgJxWkq9JQP8afOnaIG4mY rNUW83tM0U4jC5IrHzv7MvIBggWBMHgxLtOtdKOnsLO/U9kjVrausUtZZE/sVa5KM+5b bQu15bhQIwH+9Qmnp3Js6VFFqKGq+z7VgTMN9np8V+F0l0cEN2wBKd14N4KGIvHHy0dZ kYg7VO73CBikoIS1gLq0oobv9HQErz/9+brZgcKISswLFhuj3U5z4SVqPZNDYVABtIFt gHzl3YE6wqyEX1tHMwRZa9outDA2IBZ3dvqpHfvpRA0CzeQgZB1UHNGRKkn9No+9CK/Q ZOIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=qRuQ1mrwTnCrlmtDiCJXdi4p2uv0t05mrbfotbHVxP4=; b=gpJmq2fetrOcoVl82MfXk4/7izKfbQPfZzFkZCpTw5dNKU5TTPJ+4aKLLbGqrv/m+1 0Gt07UBcfCOTe2BtD7AvhWjHIMduZdvxnrDs+4pZwwFHMONeIcxYD64WGVnaOQ5g/T2H bfNxSqHkErd+hzQT3mCq/O5tSbaO5VwBZmHrjWbMHdiObQcU4BTfyOSd8lD+9Hbxx5lu RisVP6Hkjf6ie0s82dMNFQuBnfHpmUDkWPpGyg1uwRqN1pDjV723S7SfRGG4ATAAO1z+ r2z3AVIqmYWMhu78pI3TbbjkHa8On6dGu2H5/ZVUDkp9BhxKRXFTat8dHH8+mkna6a9S hBZg== X-Gm-Message-State: AOAM532+m/TJvZv/+EEVAeDwS6N4i5i50TVPRb3IH1rRa0gmZTmF4xAt 5isKDWyQK3/74dcOR6BunS2nO/OpXmxvCME9XZeMxg== X-Received: by 2002:a05:6808:f94:: with SMTP id o20mr259047oiw.121.1623255193503; Wed, 09 Jun 2021 09:13:13 -0700 (PDT) MIME-Version: 1.0 References: <20210607152806.GS4397@paulmck-ThinkPad-P17-Gen-1> <20210608152851.GX18427@gate.crashing.org> <20210609153133.GF18427@gate.crashing.org> In-Reply-To: <20210609153133.GF18427@gate.crashing.org> From: Marco Elver Date: Wed, 9 Jun 2021 18:13:00 +0200 Message-ID: Subject: Re: [RFC] LKMM: Add volatile_if() To: Segher Boessenkool Cc: Peter Zijlstra , "Paul E. McKenney" , Alexander Monakov , Linus Torvalds , Jakub Jelinek , Alan Stern , Will Deacon , Andrea Parri , Boqun Feng , Nick Piggin , David Howells , Jade Alglave , Luc Maranget , Akira Yokosawa , Linux Kernel Mailing List , linux-toolchains@vger.kernel.org, linux-arch Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 9 Jun 2021 at 17:33, Segher Boessenkool wrote: [...] > > An alternative design would be to use a statement attribute to only > > enforce (C) ("__attribute__((mustcontrol))" ?). > > Statement attributes only exist for empty statements. It is unclear how > (and if!) we could support it for general statements. Statement attributes can apply to anything -- Clang has had them apply to non-empty statements for a while. I have [[clang::mustcontrol]]/__attribute__((mustcontrol)) working, but of course it's not final but helped me figure out how feasible it is without running in circles here -- proof here: https://reviews.llvm.org/D103958 If [1] is up-to-date, then yes, I can see that GCC currently only supports empty statement attributes, but Clang isn't limited to empty [2]. [1] https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html [2] https://clang.llvm.org/docs/AttributeReference.html#statement-attributes In fact, since C++20 [3], GCC will have to support statement attributes on non-empty statements, so presumably the parsing logic should already be there. [3] https://en.cppreference.com/w/cpp/language/attributes/likely > Some new builtin seems to fit the requirements better? I haven't looked > too closely though. I had a longer discussion with someone offline about it, and the problem with a builtin is similar to the "memory_order_consume implementation problem" -- you might have an expression that uses the builtin in some function without any control, and merely returns the result of the expression as a result. If that function is in another compilation unit, it then becomes difficult to propagate this information without somehow making it part of the type system. Therefore, by using a statement attribute on conditional control statements, we do not even have this problem. It seems cleaner syntactically than having a __builtin_() that is either approximate, or gives an error if used in the wrong context. Hence the suggestion for a very simple attribute, which also side-steps this problem. Thanks, -- Marco