From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 26DA93858D20; Mon, 11 Mar 2024 11:43:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 26DA93858D20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1710157417; bh=fv9KAr/7u77lUFytJQkvM8vhehZYmhAe49UUC/M7WCg=; h=From:To:Subject:Date:From; b=XSHLdWX0yPji0IJF3paF5QEpu6wEvbaAmSWT+6t8ZVvy3sULijcFwRH6btbrl/I89 1rbUKO7xnnyjDDIbe+31GeunQ4oBtnTRqqK3A6uaOMp8HG9RTfbpEYy8Q4b+b99s+H VsJXnwNoeHGsgnUJIBaq+VX4PTPMZe1qO9zp8GMQ= From: "khim at google dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/114305] New: GCC doesn't use [[gnu::pure]] attribute on the inline function Date: Mon, 11 Mar 2024 11:43:36 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: khim at google 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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=3D114305 Bug ID: 114305 Summary: GCC doesn't use [[gnu::pure]] attribute on the inline function Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: khim at google dot com Target Milestone: --- The following program is an illustration (https://godbolt.org/z/PYW34ccvP): #include GNU_PURE1 extern size_t foo(size_t); template GNU_PURE2 inline size_t test() { return foo(size); } int test_func(int x, int y) { return test() + test(); } If GNU_PURE1 is [[gnu::pure]] then both gcc and clang optimize away second call, if GNU_PURE2 is [[gnu::pure]] then only clang does that. That means that it's impossible to add [[gnu::pure]] optimization on top of function that's pure according to the docs but is not declared as such in t= he header file.=