From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) by sourceware.org (Postfix) with ESMTPS id BAACC3858439 for ; Wed, 8 Dec 2021 18:12:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BAACC3858439 Received: by mail-ot1-x32a.google.com with SMTP id a23-20020a9d4717000000b0056c15d6d0caso3527791otf.12 for ; Wed, 08 Dec 2021 10:12:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=JuNSGWA5uQHemmecjz6kVw8pWn1tqp36F7yxqvaTUGk=; b=gk23xgx7YeSS8nqHIqYvV1vC0cvhb1VQ5wPX/asqhzbhoic9byY7KAid3v+Zh4gs3p e+Sy/JLS0QdIRxhpbP5ZkmFpb2W6SEHlXPn8XupZX1ScD17QV9/0IDjy3P3NE+jWn2br oDGVI0n51iFxH2or7ikA2ZhKJE36ehNj5NZ1MBZDvXVGVScXsxOolWXs1R4DTx6z3tLe t6SzocVEDpvdMCLXepJIFdJIbGsJQjl90XDu9RufV7Na9+dnJ2yHptuYjxlGx5GOtkL0 GNK3wx8vP2BJE91eh3D9Og3cPUPf3u/nWjkxN0pjNj/VduFiXNhyXlKkUSeMJKeEWSkf KjOA== X-Gm-Message-State: AOAM532khs/9L5xsq0F8P9tyZpUxNRG1PhwkT7MU/UpX+tR4G1ZCbrCV Q7nZDXU7A3Hn/DBW4MJbV2Qfq+qj9G4= X-Google-Smtp-Source: ABdhPJwiBOTyz/ZfeW0wUKMijYsGVhBo4G8+K1ld4IFokLorWGA/yD9kWBLwjB1VFUFPPlB9+YrLig== X-Received: by 2002:a9d:6f0e:: with SMTP id n14mr982283otq.173.1638987142970; Wed, 08 Dec 2021 10:12:22 -0800 (PST) Received: from [192.168.0.41] (184-96-227-137.hlrn.qwest.net. [184.96.227.137]) by smtp.gmail.com with ESMTPSA id o19sm848170oiw.22.2021.12.08.10.12.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Dec 2021 10:12:22 -0800 (PST) Subject: Re: [PATCH] enable -Winvalid-memory-order for C++ [PR99612] To: Jonathan Wakely Cc: gcc-patches References: From: Martin Sebor Message-ID: <16d8871f-89ac-b662-fa2a-28b2f2535d4f@gmail.com> Date: Wed, 8 Dec 2021 11:12:21 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Dec 2021 18:12:25 -0000 On 12/8/21 10:14 AM, Jonathan Wakely wrote: > On Wed, 8 Dec 2021 at 16:49, Martin Sebor wrote: >> I don't anticipate this change to lead to the same fallout >> because it's unlikely for GCC to synthesize invalid memory >> orders out of thin air; > > Agreed. I don't think we'll have the same kind of issues. 99% of uses > of memory orders just use the constants explicitly, passing them > directly to the std::atomic member functions (or something that calls > them). Ack. > >> and b) because the current solution >> can only detect the problems in calls to atomic functions at >> -O0 that are declared with attribute always_inline. This >> includes member functions defined in the enclosing atomic >> class but not namespace-scope functions. To make >> the detection possible those would also have to be >> always_inline. If that's a change you'd like to see I can >> look into making it happen. > > I think we can ignore the namespace-scope functions in . Most people do. I was thinking it would be nice to provide the same quality for the C/C++ portability interface (see the test below that triggers the warning at -O0 in C but requires -O1 to get it in C++). But it's not a big deal. Martin #if __cplusplus # include using std::memory_order_release; using std::atomic_load_explicit; extern std::atomic eai; #else # include extern _Atomic int eai; #endif int load (void) { return atomic_load_explicit (&eai, memory_order_release); }