From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BC2853856DD4; Tue, 2 Aug 2022 06:41:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC2853856DD4 From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/106502] Three calls to __attribute__((const)) function Date: Tue, 02 Aug 2022 06:41:49 +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: 13.0 X-Bugzilla-Keywords: missed-optimization 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 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, 02 Aug 2022 06:41:49 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106502 --- Comment #3 from Jonathan Wakely --- It doesn't happen unless the name() function is virtual. Reduced: extern "C" int puts(const char*); struct Cat { virtual const char* name(); }; __attribute__((const)) Cat& cat(); int main() { puts(cat().name()); } Produces this gimple: int main () { int D.2388; _1 =3D cat (); _2 =3D cat (); _3 =3D _2->_vptr.Cat; _4 =3D *_3; _5 =3D cat (); _6 =3D OBJ_TYPE_REF(_4;(struct Cat)_1->0B) (_5); puts (_6); D.2388 =3D 0; return D.2388; }=