From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 124B53858C41; Tue, 2 Jan 2024 16:08:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 124B53858C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1704211702; bh=7oeNzoc5B5WkIm9Ad2B4AhtUIzcs0hY38hfZkZ4C8rY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=RAKQokT2rLJcXPGozG8flFCJ06xhmzOO2DTN8MSczmA7qek11RNYd/pdgq+Tcsqiz T3QUHtvLqYYn6kKWrS0aKnNRGUDvEzxvrarXKX6sfws2H8C/u8p0dw8yWyZrNfyRbD 0a02I/lwYfPvE5bfl7h3TP0tKSYoUd7h6bi4FpdA= From: "stefan at bytereef dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/98753] -Wfree-nonheap-object on unreachable code with -O0 Date: Tue, 02 Jan 2024 16:08:18 +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: stefan at bytereef dot org X-Bugzilla-Status: NEW 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98753 --- Comment #16 from Stefan Krah --- I have encountered the same issue (gcc emits a false positive warning when free() is called conditionally) in the mpdecimal project when compiled with -flto. Worse, mpdecimal itself as well as a large test suite compile without warni= ngs, so distributions will think everything is fine. Until a user uses the static libmpdec.a for a trivial program: wget https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-2.5.1.tar.gz tar xvf mpdecimal-2.5.1.tar.gz cd mpdecimal-2.5.1 ./configure CFLAGS=3D"-flto=3Dauto" CXXFLAGS=3D"-flto=3Dauto" LDFLAGS=3D"-f= lto=3Dauto" LDXXFLAGS=3D"-flto=3Dauto" make # The trivial program: $ cd libmpdec $ make bench gcc -Wall -Wextra -Wno-unknown-pragmas -std=3Dc99 -pedantic -DNDEBUG -O2 -flto=3Dauto -o bench bench.c libmpdec.a -lm In function =E2=80=98mpd_del=E2=80=99, inlined from =E2=80=98_mpd_qaddsub.constprop=E2=80=99 at mpdecimal.c:34= 71:5: mpdecimal.c:470:9: warning: attempt to free a non-heap object =E2=80=98big_= aligned=E2=80=99 [-Wfree-nonheap-object] mpd_free(dec); Here, the user will get a static library to which he may not even have the source code readily available and gets a false positive warning for code in that library. Like others, I think this warning should be under a category -Wmaybe and be less decisive in its message. For the next mpdecimal release the Makefile will filter out -flto for the static library build.=