From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EB6063857C50; Tue, 26 Apr 2022 09:43:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EB6063857C50 From: "avi at scylladb dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/105373] miscompile involving lambda coroutines and an object bitwise copied instead of via the copy constructor Date: Tue, 26 Apr 2022 09:43:04 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.3.1 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: avi at scylladb dot com 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: Tue, 26 Apr 2022 09:43:05 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105373 --- Comment #6 from Avi Kivity --- Some more findings: if I replace the lambda (which is not a coroutine, but = is contained in a coroutine lambda) with an equivalent struct, the problem goes away, both at runtime and in terms of an __old4 copy.=20 + struct inner_lambda { + table* zis; + lw_shared_ptr old4; + std::vector& newtabs; + inner_lambda(table* zis, lw_shared_ptr& old3, std::vector& newtabs) + : zis(zis), old4(old3), newtabs(newtabs) {} + future<> operator()() { + tlogger.info("updating cache {}", fmt::ptr(old4.get())); + return zis->update_cache(old4, newtabs); + } + }; + tlogger.info("before updating cache {}", fmt::ptr(old3.get())); - co_await with_scheduling_group(_config.memtable_to_cache_scheduling_group, [this, ol= d4 =3D old3, &newtabs] () -> future<> { + co_await with_scheduling_group(_config.memtable_to_cache_scheduling_group, /* [this, old4 =3D old3, &newtabs] () mutable -> future<> { tlogger.info("updating cache {}", fmt::ptr(old4.get())= ); return update_cache(old4, newtabs); - }); + } */ inner_lambda(this, old3, newtabs)); tlogger.info("updating cache {} done", fmt::ptr(old3.get()= )); _memtables->erase(old3); tlogger.debug("Memtable for {}.{} replaced, into {} sstabl= es", old3->schema()->ks_name(), old3->schema()->cf_name(), newtabs.size()); tlogger.info("try_flush_memtable_to_sstable post_flush:end= old {} refcnt {}", fmt::ptr(old3.get()), old3.use_count()); co_return stop_iteration::yes;=