From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5B6EC3857C49; Tue, 11 Aug 2020 07:30:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5B6EC3857C49 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1597131004; bh=wEhq2GHsaEcmKyYWTT5VWEAkSvh/Z4CKOsKKq9RMPT0=; h=From:To:Subject:Date:From; b=UAReiivLUEZlgyB+9DptjIlyGJLgl+UQfIhMqil3ENkEOHS5to6y8oJmiUJsD1Fpi UKNiojb03Jss/35vodZn6Ix4wxPsmd9DWKa21D1XaRo4+ER+7eaTtBSjhVTzjq2fmr J/GfGv2/PrU8YvUiHRog7kM6HT9pNYkaFDEFtVWI= From: "stefansf at linux dot ibm.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/96564] New: New maybe use of uninitialized variable warning since GCC >10 Date: Tue, 11 Aug 2020 07:30:04 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: stefansf at linux dot ibm.com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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, 11 Aug 2020 07:30:04 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D96564 Bug ID: 96564 Summary: New maybe use of uninitialized variable warning since GCC >10 Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: stefansf at linux dot ibm.com Target Milestone: --- Consider the following MWE: extern void* malloc (long unsigned int); void fun (unsigned *x) { unsigned *a =3D malloc (*x); if (a =3D=3D 0) return; if (a !=3D x) // (A) *a =3D *x; *x =3D *a; } If compiled with GCC 10, then no warning is emitted. If compiled with GCC HEAD (currently 84005b8abf9), then the following warni= ng is emitted: gcc -W -c -O2 mwe.c mwe.c: In function 'fun': mwe.c:8:8: warning: '*(a)' may be used uninitialized [-Wmaybe-uninitialized] 8 | *x =3D *a; | ^~ Rational why this example is strictly speaking fine: 1) Assume x is a valid pointer. Then malloc will either return a nullpoint= er and we return, or a pointer to a fresh object which address is different fr= om any other existing object. Thus (A) always evaluates to true which means *= a is initialized. 2) Assume x is an invalid pointer. Then dereferencing x prior to the call = to malloc already results in UB. Thus the only case in which condition (A) may evaluate to false is when x i= s an invalid pointer (e.g. previously malloc'd and then free'd such that a furth= er call to malloc returns the very same address rendering (A) false) results in UB. Since this is a maybe warning I'm wondering whether this is considered a bu= g or is acceptable. Any thoughts?=