From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by sourceware.org (Postfix) with ESMTP id A1C0C3858C2C for ; Tue, 21 Dec 2021 16:40:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A1C0C3858C2C Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=kernel.crashing.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=kernel.crashing.org Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 1BLGdpJU006118; Tue, 21 Dec 2021 10:39:51 -0600 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 1BLGdo5C006117; Tue, 21 Dec 2021 10:39:50 -0600 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Tue, 21 Dec 2021 10:39:50 -0600 From: Segher Boessenkool To: Adrian Moreno Cc: Stefan Ring , gcc-help Subject: Re: broken code only when optimized "-O2" Message-ID: <20211221163950.GA614@gate.crashing.org> References: <0210178a-c875-fcbd-009f-5f438a098709@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0210178a-c875-fcbd-009f-5f438a098709@redhat.com> User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, 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: Tue, 21 Dec 2021 16:40:53 -0000 On Tue, Dec 21, 2021 at 05:13:08PM +0100, Adrian Moreno via Gcc-help wrote: > On 12/21/21 17:05, Stefan Ring wrote: > >On Tue, Dec 21, 2021 at 4:40 PM Adrian Moreno via Gcc-help > > wrote: > >> > >>I'd really appreciate any hint or idea to try to understand this problem. > > > >I guess the compiler doesn't like the dereferencing of uninitialized > >pointers (in the sizeof expressions). I am not 100% sure that this > >counts as dereferencing, but I would assume so. Because of this the > >compiler will be free to behave however it likes to. > > I agree that doesn't look good. Replacing them by sizeof (struct ___) > expressions does not change the behavior though. As required by C. 6.3.2.1/2: Except when it is the operand of the sizeof operator, [...], an lvalue that does not have array type is converted to the value stored in the designated object (and is no longer an lvalue); this is called lvalue conversion. There is no dereferencing. Segher