public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/114305] New: GCC doesn't use [[gnu::pure]] attribute on the inline function
@ 2024-03-11 11:43 khim at google dot com
  2024-03-11 12:04 ` [Bug middle-end/114305] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: khim at google dot com @ 2024-03-11 11:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114305

            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 <cstddef>

GNU_PURE1 extern size_t foo(size_t);

template <size_t size>
GNU_PURE2 inline size_t test() {
    return foo(size);
}

int test_func(int x, int y) {
    return test<sizeof x>() + test<sizeof y>();
}

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 the
header file.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug middle-end/114305] GCC doesn't use [[gnu::pure]] attribute on the inline function
  2024-03-11 11:43 [Bug c++/114305] New: GCC doesn't use [[gnu::pure]] attribute on the inline function khim at google dot com
@ 2024-03-11 12:04 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-11 12:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114305

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |DUPLICATE
           Keywords|missed-optimization         |
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Dup.

*** This bug has been marked as a duplicate of bug 47255 ***

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-03-11 12:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-11 11:43 [Bug c++/114305] New: GCC doesn't use [[gnu::pure]] attribute on the inline function khim at google dot com
2024-03-11 12:04 ` [Bug middle-end/114305] " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).