From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mengyan1223.wang (mengyan1223.wang [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 57951385842D for ; Wed, 22 Dec 2021 10:36:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 57951385842D Received: from [IPv6:240e:358:11f8:5b00:dc73:854d:832e:3] (unknown [IPv6:240e:358:11f8:5b00:dc73:854d:832e:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@mengyan1223.wang) by mengyan1223.wang (Postfix) with ESMTPSA id A8391660F4; Wed, 22 Dec 2021 05:36:43 -0500 (EST) Message-ID: <9eb235680e05e02f8ac6589a52d1996b3cfc0bb5.camel@mengyan1223.wang> Subject: Re: broken code only when optimized "-O2" From: Xi Ruoyao To: Adrian Moreno , Florian Weimer , Adrian Moreno via Gcc-help Cc: David Brown Date: Wed, 22 Dec 2021 18:36:37 +0800 In-Reply-To: References: <9b28799e-71f8-2ef9-1cc9-01345993cc11@redhat.com> <877dbx7x47.fsf@oldenburg.str.redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3031.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, JMQ_SPF_NEUTRAL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=no 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-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Dec 2021 10:36:49 -0000 On Wed, 2021-12-22 at 11:34 +0100, Adrian Moreno via Gcc-help wrote: > > > On 12/22/21 11:27, Florian Weimer wrote: > > * Adrian Moreno via Gcc-help: > > > > > So here I do not know what the compiler would think about "pos" if > > > it > > > happens to point to some invalid stack address. > > > > In such cases, the compiler typically assumes that the code in > > question > > is never executed.  This means that the comparison does not need to > > be > > performed, among other things. > > > > So it wouldn't cause undefined behavior? It *is* undefined behavior, and the compiler can remove any execution paths which will eventually hit an undefined behavior. -- Xi Ruoyao School of Aerospace Science and Technology, Xidian University