From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9ABFC3858C2F; Mon, 17 Apr 2023 08:15:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9ABFC3858C2F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1681719344; bh=i70wLyQmt5aRrkFJhQP+1TYLQjovh8kFeJIL34D5D3Y=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ISXCUoCfIgjG5MLw/6rZVlkFeObfOcz2mhYYtX9iU7izs5wW8J+lTpNu0mHhVh9DH fiTf8VYRCMMQ7aFlQbBCslkVcwYBPvIE0M4yjOisSXdMKWwg25qH+3ykfySHpUMOdf /trPCQjjs1EOZZoh0Cpz85XnF/G13nG4hWsTDptI= From: "daniel.klauer at gin dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/95825] [10/11/12/13 Regression] boost::optional -Wuninitialized with -fsanitize=address Date: Mon, 17 Apr 2023 08:15:44 +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: 10.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: daniel.klauer at gin dot de X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: 10.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc 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=3D95825 daniel.klauer at gin dot de changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |daniel.klauer at gin dot de --- Comment #7 from daniel.klauer at gin dot de --- Reduced test case: template struct tc_optional_base { // default ctor leaves m_storage uninitialized tc_optional_base() : m_initialized(false) {} bool m_initialized; T m_storage; }; template tc_optional_base f() { return {}; } tc_optional_base g() { return f(); } $ g++ -Wall -O1 -fsanitize=3Daddress b.cxx -c In function =E2=80=98tc_optional_base f() [with T =3D int]=E2=80=99, inlined from =E2=80=98tc_optional_base g()=E2=80=99 at b.cxx:18:15: b.cxx:13:17: warning: =E2=80=98.tc_optional_base::m_storage= =E2=80=99 is used uninitialized [-Wuninitialized] 13 | return {}; | ^ b.cxx: In function =E2=80=98tc_optional_base g()=E2=80=99: b.cxx:13:17: note: =E2=80=98=E2=80=99 declared here 13 | return {}; | $ g++ --version g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0 It looks like the m_storage field really is uninitialized, although I think= in practice boost::optional does not access it in that state in its implementa= tion thanks to m_initialized. Does gcc warn about the uninitialized data during copying of the object here? It does seem to be correct... In the above case with templates it happens at -O1 already, but without templates it happens too, at -O2.=