From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 48E84386F465; Tue, 23 Jun 2020 00:21:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 48E84386F465 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592871705; bh=oqfPXY6jRAKoekneCwZO84gl4TYxudkSWJGyQIE+Y3o=; h=From:To:Subject:Date:In-Reply-To:References:From; b=d2i0va4bTuRRh2gbpUn5jnowYMzHNub2i3sSKcjV26Z/s5DWj5HPB6egmWT8BBmZ4 /GfcAAPUVADxypwrz4zbuPaPYwpPmus0+TLuiGc3j5FsPR+eE9cuexkKFK+orESsb6 dVx53brAVM0cbLAs+PjLeEc/Ca+VeYEi1WRT99y8= From: "msebor at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/95818] wrong "used uninitialized" warning Date: Tue, 23 Jun 2020 00:21:45 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: msebor at gcc dot gnu.org X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: component resolution cc bug_status Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Jun 2020 00:21:45 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D95818 Martin Sebor changed: What |Removed |Added ---------------------------------------------------------------------------- Component|c |middle-end Resolution|--- |INVALID CC| |msebor at gcc dot gnu.org Status|WAITING |RESOLVED --- Comment #6 from Martin Sebor --- This instance of the warning looks familiar but I can't reproduce it with my build of the kernel. The code in the test case isn't valid (it triggers bo= th -Wstrict-aliasing and -Wuninitialized), and I don't think it's safe either.= =20 Only the leading 48 bits of the struct are initialized (by GCC; the program initializes just 35 bits) but the access is to the full 64 bits. Clearing = the whole struct by calling memset avoids the -Wuninitialized. A small test case that reproduces both warnings is below. $ cat z.c && gcc -O2 -S -Wall -fdump-tree-uninit=3D/dev/stdout z.c struct S { int a; short i: 1; }; void f (long); void g (void) { struct S s; s.a =3D 0; s.i =3D 1; f (*(long*)&s); } z.c: In function =E2=80=98g=E2=80=99: z.c:14:7: warning: dereferencing type-punned pointer will break strict-alia= sing rules [-Wstrict-aliasing] 14 | f (*(long*)&s); | ^~~~~~~~~ z.c:14:3: warning: =E2=80=98s=E2=80=99 is used uninitialized [-Wuninitializ= ed] 14 | f (*(long*)&s); | ^~~~~~~~~~~~~~ z.c:11:12: note: =E2=80=98s=E2=80=99 declared here 11 | struct S s; | ^ ;; Function g (g, funcdef_no=3D0, decl_uid=3D1937, cgraph_uid=3D1, symbol_o= rder=3D0) g () { struct S s; long int _1; [local count: 1073741824]: s.a =3D 0; s.i =3D -1; _1 =3D MEM[(long int *)&s]; f (_1); [tail call] s =3D{v} {CLOBBER}; return; }=