From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A3D953858C53; Fri, 2 Jun 2023 03:43:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3D953858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685677439; bh=Dbx/6BXKyPY/qdDkcolQdtRqQcWixvz58criGd3X0jE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=D/9/rbAQu52czQTUK5l0cw8stB/cXmkTFLnWBq8T6c+w+H/bIvp3IgY1M4ETicydf MTio5WG88Wim9BWlMpaDN0J/hkdzJrnRMlPPGzPFhbW0FCOrHAmOOWhsSEgQFMv7Tm pvZHUxwxmyXM1WvlHB6tKkf4yPmcsEERGTomJiNA= From: "yongxiangng at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug ipa/110057] Missed devirtualization opportunities Date: Fri, 02 Jun 2023 03:43:58 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: ipa X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: yongxiangng at gmail 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110057 --- Comment #6 from Ng YongXiang --- That is interesting. Thanks for the reply. However, I'd argue that the 2 bugs mentioned are different from what I am proposing. The 2 bugs linked access virtual functions via ptr (delete p; val->f();) and are invoked by the user directly, and so I think it makes se= nse for the compiler to access the vtable.=20 However, the array issue I'm putting forth is caused by the destruction of = the array with automatic storage duration, and the destruction code is generate= d by the compiler not by the user via some kind of ptr or reference. Moreover, clang does it right and devirtualizes the destruction of the array while gcc still doesn't. https://godbolt.org/z/f33Gh5EGM #include #include struct A { A() { std::cout << "A()" << std::endl; } virtual ~A()=20 { std::cout << "~A()" << std::endl; } }; struct B : public A { B() { std::cout << "B()" << std::endl; } virtual ~B() { std::cout << "~B()" << std::endl; } }; int main() { A a[3]; a[0].~A(); :: new(std::addressof(a[0])) B(); }=