From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4F228386186E; Sun, 27 Dec 2020 01:39:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4F228386186E From: "alexmudmiko at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/80635] [8/9/10/11 regression] std::optional and bogus -Wmaybe-uninitialized warning Date: Sun, 27 Dec 2020 01:39:47 +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: 8.2.0 X-Bugzilla-Keywords: diagnostic, patch X-Bugzilla-Severity: normal X-Bugzilla-Who: alexmudmiko at gmail dot com X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: law at redhat dot com X-Bugzilla-Target-Milestone: 8.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 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: Sun, 27 Dec 2020 01:39:53 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D80635 Miko Vich changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |alexmudmiko at gmail dot c= om --- Comment #56 from Miko Vich --- I think Jeff is correct. While I have no experience with writing compilers, I've been wrestling with this "feature" for about 3 years now. What's odd = is that it doesn't always manifest. It also seems to be restricted (at least = in my cases) to using std::optional with POD or enum types. Also, the volatile thingy doesn't solve the issue if sizeof(T) is less than 16 bytes. (Again my experience.) Anyway... some findings which I think support Jeff's comment: about a year= ago I went so far as to memset to zero the memory in std::optional for sizeof(T= ).=20 This made the warning go away... defeats the purpose of optional of course,= but no more warning. But on inspecting the assembly generated, there was no zero-ing of the memory (or any other assignment to 0). So the optimizer no longer error'd on maybe-uninitialized, but knew enough to elide away the memset. So... is this maybe a case of the warning simply being emitted too soon in = the passes, i.e., before its completely finished optimizing? Because even with= out the memset change, the final assembly generated under -O3 never has a path where the value in the optional is accessed when uninitialized.=