From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 58E863858404; Tue, 5 Mar 2024 15:05:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 58E863858404 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709651154; bh=2SUXIrDLLZz3EK6+3SD8FTnmHAVLwrTeeleX6IYBAEY=; h=From:To:Subject:Date:In-Reply-To:References:From; b=EfLBFPOPpSG8TzXMTCeCcKAVEf/xg0Y10nZDqxq59fy7A/V1bjxtqJaPlCQyRKL3D UuU1RBwZtrwo9vlHpxrjfQJcRh2IRnFtWtR45Q8jQEQmxeJ7RU6mN4m63EJ2dt1bHl dzb8yKNmwU2IHEKXPLE7/1p+ABA6skA7WANRo8fg= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/112307] Segmentation fault with -O1 -fcode-hoisting Date: Tue, 05 Mar 2024 15:05:52 +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: 14.0 X-Bugzilla-Keywords: needs-reduction, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.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=3D112307 --- Comment #5 from Jonathan Wakely --- return EnumeratorRange(Enumerator(std::views::single(Intersection()))); This creates a temporary Intersection object, then copies that into a single_view object. Then that is copied into an Enumerator object which loo= ks like: Enumerator { single_view range_; optional::_Iterator> begin_; }; The range_ member is the copy of std::views::single(Intersection()) and the begin_ member is initially empty. Then that Enumerator is copied into an EnumeratorRange which calls Next() on the new copy, which sets its begin_ member to point to the range_ member. T= hen the EnumeratorRange is returned. So I think it's expected that the Enumerator points to itself, because of t= he call to its Next() member. BUT, the self-referential pointer is set to the address of the range_ member before the return value is copied, and so goes out of scope when that objec= t is copied via registers and then copied again into the automatic variable in main(). So yes, I think it's invalid for the same reason as PR 109945 comment 25 explains, and indeed giving any of the objects a non-trivial destructor prevents it being copied via registers and so the pointer isn't invalidated= .=