From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 19307385841C for ; Wed, 22 Dec 2021 16:05:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 19307385841C Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-609-8nWtDqoiNG22kdXUAEYOxw-1; Wed, 22 Dec 2021 11:05:13 -0500 X-MC-Unique: 8nWtDqoiNG22kdXUAEYOxw-1 Received: by mail-wm1-f72.google.com with SMTP id v62-20020a1cac41000000b0033719a1a714so864633wme.6 for ; Wed, 22 Dec 2021 08:05:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=HEQmOkpY1yM6RlRx3EEgWiLJmda5T6vdua7EvRTOuvU=; b=nalHLwb+C9B7epaeuADdY4zMeQg10BYARAxNxxoxWAI1B3FKpFlzXAefUWcozh5o5h w4Q3dNtLqxUPnCpHJboK/9BD7392otlFf1JZaqh0eFMkKlxJiEF7JxuK1+UpYZGJx+Eu 3sDtprOKgQl/X4UorpG9bsGYTBEzwgK+iFCPEWWY7SzpgMUXnaVJAI5r8fdxS7S/vO1D I+uNlMwgk5zfCyteBvmadspLyOIHQF1bWqJNB2pp2jCkoWYBkZqaD0SPtZyBSjr9+fad LeWljWOfeV0lLuOtKZ0VmpsygD5ifpa2q2TPVyZqq3rhJtV/pygoBud+oxK+GrTXn/vb +22g== X-Gm-Message-State: AOAM532/vWFGiPP0/WhTvNB1hoW6xTY6IY09vjG8QE5qIpkps7YGLrY8 yEQbI9FpLfol8HcnjkTPhYaqmwztpY5drC5qYD123BwdCa8woadJth2Evyj3yxwgMi8OI4NT1ZV WZLW97Ra4/L7oDQ== X-Received: by 2002:adf:f7d2:: with SMTP id a18mr2610947wrq.354.1640189112425; Wed, 22 Dec 2021 08:05:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJy3CjoORlQPELXdg0+ZODVnqMrtbQQqEQJLQygjR18jcqTlYxeQJc+gk5kgiG9ZpaB/SezXVw== X-Received: by 2002:adf:f7d2:: with SMTP id a18mr2610926wrq.354.1640189112222; Wed, 22 Dec 2021 08:05:12 -0800 (PST) Received: from [192.168.0.129] ([81.0.47.68]) by smtp.gmail.com with ESMTPSA id u12sm2337717wrf.60.2021.12.22.08.05.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Dec 2021 08:05:11 -0800 (PST) Message-ID: Date: Wed, 22 Dec 2021 17:05:09 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.0 Subject: Re: broken code only when optimized "-O2" To: Xi Ruoyao , Florian Weimer , Adrian Moreno via Gcc-help Cc: David Brown References: <9b28799e-71f8-2ef9-1cc9-01345993cc11@redhat.com> <877dbx7x47.fsf@oldenburg.str.redhat.com> <9eb235680e05e02f8ac6589a52d1996b3cfc0bb5.camel@mengyan1223.wang> From: Adrian Moreno In-Reply-To: <9eb235680e05e02f8ac6589a52d1996b3cfc0bb5.camel@mengyan1223.wang> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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-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 16:05:16 -0000 On 12/22/21 11:36, Xi Ruoyao wrote: > 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. > Thanks for confirming. -- Adrián Moreno