From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id C9A533858289 for ; Sun, 13 Nov 2022 18:40:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C9A533858289 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-pl1-x630.google.com with SMTP id p21so8226052plr.7 for ; Sun, 13 Nov 2022 10:40:18 -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=Ozsw1JvuU9ZdWN4JVdMNnyNC+4iATXWg5SOXmeb0nVA=; b=X6HTg4YnyI8OUi3RYxiKD+hafocWR0CKZQXY1vJGApYnHQM+r/pCBCnUgjLaEhgrRt nzl7kyidcIuBZtwsEggSie2IV+hC4NatEZOix+IoJRx03CrI9LU/4wgvPSzAo9rr0UD+ X1yV1OBVbh0+AIARx/w1tcvQ8a3sXvx0BHf3sf8lDE8//5Amk6weQX9+dCUKtJEA6wha h+v4p730XFoDMKAJZ2ZYG03FAFeR0xaRvgfifuL+5movrqDi95lPqwsTW1m9bi9AhkEu 2jY884vlFFvXYz/D9bfsZ7a2MG90Il7RoeT1i0hyqQEwIsgGLC8Hn06HN9X2TmfzpPby Yh/A== 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=Ozsw1JvuU9ZdWN4JVdMNnyNC+4iATXWg5SOXmeb0nVA=; b=shCBP1/3tPqsfj7jCknviQGdpb1o/tWEc7X/WqSP7XsggUTUrvItusKm/EvQ53WPMv u7aUpSCGmLbAEzyCPvgqdjl98+vEEhG4BHDOTVtHAr98kXSj/DHP50BHrUTK+dZm8LQc SCf05kAlX/PueNPc2iGCzI5o8DSp9xgudcud2+Sjafduw4R/s8gQB0SigES+fkrz2u57 o57/sNdyYYstAUMvOGQtjk3nGkQJVEibon/s3mLYYwOEfYHWNWojo43VrtNNUzBwc1gR pnHayVn3jlik4ahszbrSZHv2r0R/CMIW7RY2YgldaMXEZk5Ux6+peWAgbifjHoXLKAk6 naWw== X-Gm-Message-State: ANoB5pnK+wvjYUTiEs8I2s4xOy8Yz3WVd4vhtUVumQ8nTSWhHGJbgEnq vv2AgSZNHin75G6kEgA1Ovwhdr7DAMF+hLO41DY= X-Google-Smtp-Source: AA0mqf6Y6ZxNEmJ+da9VjVXtSc03RM/JtxtJU5Kljkk4eMBRZbnBLFp4M33RVwtbiCc1j0SaR6BsK4a23jIYIh6pJ0E= X-Received: by 2002:a17:902:da86:b0:188:62b7:1d6b with SMTP id j6-20020a170902da8600b0018862b71d6bmr10800827plx.106.1668364817678; Sun, 13 Nov 2022 10:40:17 -0800 (PST) MIME-Version: 1.0 References: <9711434a-daff-5422-d69b-2c8eaca5ad1e@gmail.com> In-Reply-To: <9711434a-daff-5422-d69b-2c8eaca5ad1e@gmail.com> From: Andrew Pinski Date: Sun, 13 Nov 2022 10:40:05 -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=-2.3 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:36 AM Alejandro Colomar via Gcc wrote: > > Hi, > > While discussing some idea for a new feature, I tested the following exam= ple > 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 ther= e. See https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Warning-Options.html#inde= x-Winit-self https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/Warning-Options.html#index-Wu= ninitialized "If you want to warn about code that uses the uninitialized value of the variable in its own initializer, use the -Winit-self option." 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 within = 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 warning= . The > analyzer is quite unreadable compared to normal warnings. > > Cheers, > Alex > > -- >