From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from spam02.hesby.net (spam01.hesby.net [81.29.32.152]) by sourceware.org (Postfix) with ESMTP id 79D3B3858D39 for ; Tue, 11 Jan 2022 18:17:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 79D3B3858D39 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=hesbynett.no Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=hesbynett.no Received: from [192.168.4.227] (247.92-221-34.customer.lyse.net [92.221.34.247]) by spam02.hesby.net (Halon) with ESMTPSA id b3575f84-730a-11ec-8d7a-506b8dfa0e58; Tue, 11 Jan 2022 19:17:16 +0100 (CET) Subject: Re: reordering of trapping operations and volatile To: Richard Biener , Martin Uecker Cc: "gcc@gcc.gnu.org" References: <832b1b3957a0243ca37378a774effe537642eed3.camel@gmail.com> <40fd9a2f078cd6e87fedbc5f1e77baf8445a7356.camel@gmail.com> From: David Brown Message-ID: <80181458-a864-57ea-47f0-adeedd2f7236@hesbynett.no> Date: Tue, 11 Jan 2022 19:17:13 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3033.3 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, NICE_REPLY_A, 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@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, 11 Jan 2022 18:17:21 -0000 On 11/01/2022 08:11, Richard Biener via Gcc wrote: > On Mon, Jan 10, 2022 at 6:36 PM Martin Uecker wrote: >> > > I realize that UB in a + b isn't (usually) observable but > UB resulting in traps are. > > So I'm still wondering why you think that 'volatile' makes > a critical difference we ought to honor? I don't remember > 'volatile' being special in the definition of the abstract > machine with regarding to observability (as opposed to > sequence points). > > Actually, volatile accesses /are/ critical to observable behaviour - observable behaviour is program start and termination (normal termination flushing file buffers, not crashes which are UB), input and output via "interactive devices" (these are not defined by the standard), and volatile accesses. (See 5.1.2.3p6 in the standards if you want the details. Note that in C18, "volatile access" was expanded to include all accesses through volatile-qualified lvalues.) However, undefined behaviour is /not/ observable behaviour. It can also be viewed as not affecting anything else, and so moving it does not affect volatile accesses. So you can't re-order two volatile accesses with respect to each other. But you /can/ re-order UB with respect to anything else, including volatile accesses. (IMHO) "Performing a trap" - such as some systems will do when dividing by 0, for example - is not listed as observable behaviour.