Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp893832pxb; Wed, 27 Oct 2021 14:37:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuQzTtF/yNoDzxid0umvE0Hgvhlh/hel+zzOFDuIegyx+b+QxQw0WDFIThohDz9jAQyDh4 X-Received: by 2002:a17:906:ce4f:: with SMTP id se15mr147946ejb.482.1635370658607; Wed, 27 Oct 2021 14:37:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635370658; cv=none; d=google.com; s=arc-20160816; b=r1r+AXpdjRQGquTeVRIzOqnN5/r0t/+CZ8wKwtSnJkzdWC0aRdVNRMw9y0uG79qoWY Kwed3eayEHuVIEzHBRvdWffpi/IPam1VPljNxKUEuNsqwkapgN0vttmmH+3kMTUqH0cK xNKTFIIIJdbf0y+FA/mFQ1B6fF0xPrjnMlJFR/Dpu2YlkXuvoD4F7suCBbgBrpe3C1Kv l5g2dNHb07ayzXPa6m1SHRhjefTOO//DAS9lFTAy1OGxGOv+D0mj/dw9pBLP5wsjSSZu MePef28POZ+e7agJelCZG5w237p1ow8Y3u+bAY7093yz7lMmXiXOpZdxf6pu5ugGSGyn Ucbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=SUzrCsngPkseHgVZnQqs9Xm9/+E6B239ohUBqJ+ywfs=; b=pqDDZKhuUpmoMtb84qCW1jfS/AzlClpnegHbnPSlZO9chQFrYPFLCEpeW+0CNhzBmp mVTsg4kJ86AwG+2kea/8JmAA0N5AuFyvAA3erhWASTV4D0x6rUY5bT1LwxWHtPrZPOnk JwtiKcvSeipVySEqvGio8sdWlNaPdg8l6BicVoY9xDKViDSslwAb1f6pkprTg/T3WfYd muZouDhe092Jwt562khaR1GTO7r8U6ShTJzgZrcaPC9oB1m+LZ3Xas91squ7wEWho0c1 2xpUJXvTqRxFW8zoYRFWTcvT/YKNCOtDb/ZUCEaNJ9L7kcXOpiv6UZpOJnGMpodELbKc 69Yg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y22si1659234edc.353.2021.10.27.14.37.16; Wed, 27 Oct 2021 14:37:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244043AbhJ0UvK (ORCPT + 97 others); Wed, 27 Oct 2021 16:51:10 -0400 Received: from wtarreau.pck.nerim.net ([62.212.114.60]:45228 "EHLO 1wt.eu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234080AbhJ0UvJ (ORCPT ); Wed, 27 Oct 2021 16:51:09 -0400 Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 19RKmVl6012304; Wed, 27 Oct 2021 22:48:31 +0200 Date: Wed, 27 Oct 2021 22:48:31 +0200 From: Willy Tarreau To: Alan Stern Cc: Kernel development list Subject: Re: GCC not detecting use of uninitialized variable? Message-ID: <20211027204831.GB12219@1wt.eu> References: <20211027201249.GA1326060@rowland.harvard.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211027201249.GA1326060@rowland.harvard.edu> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 27, 2021 at 04:12:49PM -0400, Alan Stern wrote: > The following code does not generate a warning when compiled with GCC > 11.2.1: > > > int foo; > > void cc_test(void) > { > int a, b; > > a = 0; > a = READ_ONCE(foo); // Should be: b = READ_ONCE(foo) > do { > a += b; > b = READ_ONCE(foo); > } while (a > 0); > WRITE_ONCE(foo, a); > } > > > But if the loop is changed to execute only once -- replace the while > test with "while (0)" -- then gcc does warn about the uninitialized use > of b. > > Is this a known problem with gcc? Is it being too conservative about > detecting uses of uninitialized variables? I already had similar issues not being detected in loops. I guess the reason is simple: it might not be trivial for the compiler to prove that the value was not set on any path leading to the first use, because one of these paths is the loop itself after the instruction was assigned. I've been so much used to it that I think it has always been there and I can live with it. Willy