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=-13.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL 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 E346EC48BCF for ; Wed, 9 Jun 2021 16:14:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC44E610A2 for ; Wed, 9 Jun 2021 16:14:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233389AbhFIQQY (ORCPT ); Wed, 9 Jun 2021 12:16:24 -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-Google-Smtp-Source: ABdhPJy0aaRJDIEfrAc8IuS9AgejNj9IbDlp4XC+Now9FaX0E8vRG8TSCKUChNwRdFLPMQaGCjIcEfhKZiRDzMkBNeI= 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