From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 67D733858416; Mon, 17 Jan 2022 17:29:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 67D733858416 From: "slyfox at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/104069] -Werror=use-after-free false positive on elfutils-0.186 Date: Mon, 17 Jan 2022 17:29:11 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: slyfox at gcc dot gnu.org 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: 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: Mon, 17 Jan 2022 17:29:11 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104069 --- Comment #2 from Sergei Trofimovich --- Similar code triggers the same warning (and error due to -Werror) on current linux.git: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/too= ls/lib/subcmd/subcmd-util.h?id=3D0c947b893d69231a9add855939da7c66237ab44f#n= 50 static inline void *xrealloc(void *ptr, size_t size) { void *ret =3D realloc(ptr, size); if (!ret && !size) ret =3D realloc(ptr, 1); if (!ret) { ret =3D realloc(ptr, size); if (!ret && !size) ret =3D realloc(ptr, 1); if (!ret) die("Out of memory, realloc failed"); } return ret; } CC tools/objtool/help.o In file included from help.c:12: In function 'xrealloc', inlined from 'add_cmdname' at help.c:24:2: subcmd-util.h:56:23: error: pointer may be used after 'realloc' [-Werror=3Duse-after-free] 56 | ret =3D realloc(ptr, size); | ^~~~~~~~~~~~~~~~~~ subcmd-util.h:52:21: note: call to 'realloc' here 52 | void *ret =3D realloc(ptr, size); | ^~~~~~~~~~~~~~~~~~ subcmd-util.h:58:31: error: pointer may be used after 'realloc' [-Werror=3Duse-after-free] 58 | ret =3D realloc(ptr, 1); | ^~~~~~~~~~~~~~~ subcmd-util.h:52:21: note: call to 'realloc' here 52 | void *ret =3D realloc(ptr, size); | ^~~~~~~~~~~~~~~~~~=