public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/113203] New: __attribute__ ((always_inline)) fails with C99/LTO/-Og.
@ 2024-01-02 16:54 stefan at bytereef dot org
  2024-01-03  1:57 ` [Bug ipa/113203] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: stefan at bytereef dot org @ 2024-01-02 16:54 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113203
           Summary: __attribute__ ((always_inline)) fails with
                    C99/LTO/-Og.
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: stefan at bytereef dot org
  Target Milestone: ---

This is similar to #107931. I'm opening a new issue because there are no
indirect function calls and the problem occurs with -std=c99 -flto -Og.


foo.c
========================================================
#include <stdbool.h>
#include "foo.h"

inline __attribute__ ((always_inline)) bool
f(int x)
{
  return (x > 2);
}
========================================================

foo.h
========================================================
#include <stdbool.h>
bool f(int);
========================================================

main.c
========================================================
#include <stdio.h>
#include "foo.h"

int
main(int argc, char *argv[])
{
   (void)argv;

   if (f(argc)) {
     puts("yes");
   }
   else {
     puts("no");
   }

   return 0;
}
========================================================



$ gcc -Wall -Wextra -std=c99 -flto -Og -o main foo.c main.c

foo.c: In function ‘main’:
foo.c:5:1: error: inlining failed in call to ‘always_inline’ ‘f’: function not
considered for inlining
    5 | f(int x)
      | ^
main.c:9:8: note: called from here
    9 |    if (f(argc)) {
      |        ^
lto-wrapper: fatal error: /home/skrah/gcc/bin/gcc returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed




This is extracted from the mpdecimal project that has used C99 and
always_inline for a decade without problems. The code was written before the
amendment to the always_inline documentation in 2014 and always_inline has
consistently produced a speedup of 1-2.5% even with -O3.


My questions:

1) Since this is C99, should always_inline work without errors when -std=c99 is
active? If not, should -std=c99 reject always_inline?

2) There is a clear demand for something like "really_inline" that ignores the
heuristics and just inlines whenever possible without errors or warnings. In
practice that is how MSVC __forceinline or clang always_inline behave. Could
that be added?

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

end of thread, other threads:[~2024-01-08  9:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-02 16:54 [Bug c/113203] New: __attribute__ ((always_inline)) fails with C99/LTO/-Og stefan at bytereef dot org
2024-01-03  1:57 ` [Bug ipa/113203] " pinskia at gcc dot gnu.org
2024-01-03  2:05 ` pinskia at gcc dot gnu.org
2024-01-03  8:35 ` jakub at gcc dot gnu.org
2024-01-03 16:26 ` stefan at bytereef dot org
2024-01-08  9:16 ` rguenth 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).