From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 9FBE23857835 for ; Sun, 13 Nov 2022 18:41:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9FBE23857835 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-x42b.google.com with SMTP id 130so9133947pfu.8 for ; Sun, 13 Nov 2022 10:41:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=y3usJ2NaEJunjrc82OrYKBenIMx5/jfyhpbSlQGE8xs=; b=j3OYV30XyN+TnvMuP9j4ebfMk2TH10EsoT2VzEsLVT00AF01Aq3xvQcNDHUZhnOXct Q1PGEk+zxyOoPxDxsbRhW2RveWSGqeFggEM58vEE4y3C49nGnlDc7PbcYPseJbb50Glw pAW+MbliiZTlMGQlV6V5wmUPujGzCl0PGd7D3PjXhD5+NFrbxMv9KO9QOnIuzUu+aecr GG7E4tPC21BSYM7Im+n4ZtD8AKi8auAOuX5HVzK/wq+QQksoWOhKaJfKIleeOUw1PgYL DMJRFQWRApB9pwHxy6qxcnLK7oDDFoAgS6P2LaOO2p/0IgWP7DpjtQLuLTvKrjpgNXNj w5Eg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y3usJ2NaEJunjrc82OrYKBenIMx5/jfyhpbSlQGE8xs=; b=KYqbqWpgH8tvsS8iiBKCJKXNOudNQl4lKzounOui/JVmtYcys8hIa5dDkbVtmtf/Qg /1ved/h2QDJTrahCtiQ96kyEUQCU/N5lMDSXOlfySLmlr+a3sR8Gd97YulUkoycFxNeL zOzE0o5sgNcLR17C+16wlATaG4ibl/z8D5bGRiHc7ggZbCvcqE6GJpQukcBk1X/+vVXg aDG17W/lLbGcWKIo7LN8MBrqnC56gE/KUr+JASZIGfFnBGuYh35n2zv6VcthoW5tx/IF smMqUKMdHQapKiMPIx2t8U1I+CySUmWHbE793AzxdB4vZU82D61ntUm1ZKLfueGFEXFr +iOA== X-Gm-Message-State: ANoB5pnuOBedMrMkh/ewA40oUZeEcAQLyC2ncHFtR3Bm/Vgfk6W857/o 4JjjZEgTNrQVb6M7u74OF8s2DU9tegYw5ZsLfU8= X-Google-Smtp-Source: AA0mqf49NyucZGdOcNfctRHasxHYXAcYi8vkjvIO2xBUs/Fi6Vu18QJJanGzK1b9UwLPSRJ8N5B5ThjQK1SduwFt3/M= X-Received: by 2002:a63:5265:0:b0:46f:b030:4011 with SMTP id s37-20020a635265000000b0046fb0304011mr9352566pgl.277.1668364885236; Sun, 13 Nov 2022 10:41:25 -0800 (PST) MIME-Version: 1.0 References: <9711434a-daff-5422-d69b-2c8eaca5ad1e@gmail.com> In-Reply-To: From: Andrew Pinski Date: Sun, 13 Nov 2022 10:41:13 -0800 Message-ID: Subject: Re: [BUG] -Wuninitialized: initialize variable with itself To: Alejandro Colomar Cc: gcc@gcc.gnu.org, Martin Uecker , Joseph Myers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Sun, Nov 13, 2022 at 10:40 AM Andrew Pinski wrote: > > On Sun, Nov 13, 2022 at 10:36 AM Alejandro Colomar via Gcc > wrote: > > > > Hi, > > > > While discussing some idea for a new feature, I tested the following ex= ample > > program: > > > > > > int main(void) > > { > > int i =3D i; > > return i; > > } > > This is NOT a bug but a documented way of having the warning not being th= ere. > See https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Warning-Options.html#in= dex-Winit-self > https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Warning-Options.html#index-= Wuninitialized > "If you want to warn about code that uses the uninitialized value of > the variable in its own initializer, use the -Winit-self option." I should note the main reason why I Know about this is because I fixed this feature years ago (at least for C front-end) and added the option to disable the feature. > > Thanks, > Andrew Pinski > > > > > > > It seems obvious that it should give a warning, and in Clang it does: > > > > > > $ clang --version | head -n1 > > Debian clang version 14.0.6 > > > > $ clang -Wall -Wextra foo.c > > foo.c:3:10: warning: variable 'i' is uninitialized when used withi= n its own > > initialization [-Wuninitialized] > > int i =3D i; > > ~ ^ > > 1 warning generated. > > > > > > But for GCC it looks fine: > > > > $ gcc --version | head -n1 > > gcc (Debian 12.2.0-9) 12.2.0 > > > > $ gcc -Wall -Wextra foo.c > > $ > > > > > > Until you enable the analyzer, which catches the uninitialized use: > > > > > > $ gcc -fanalyzer foo.c > > foo.c: In function =E2=80=98main=E2=80=99: > > foo.c:3:13: warning: use of uninitialized value =E2=80=98i=E2=80= =99 [CWE-457] > > [-Wanalyzer-use-of-uninitialized-value] > > 3 | int i =3D i; > > | ^ > > =E2=80=98main=E2=80=99: events 1-2 > > | > > | 3 | int i =3D i; > > | | ^ > > | | | > > | | (1) region created on stack here > > | | (2) use of uninitialized value =E2=80=98i= =E2=80=99 here > > | > > > > > > > > I expect that GCC should be able to detect this bug with a simple warni= ng. The > > analyzer is quite unreadable compared to normal warnings. > > > > Cheers, > > Alex > > > > -- > >