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

            Bug ID: 126187
           Summary: C vs. C++ Optimization Level Attribute Mismatch when
                    -std=c23 is used with C code.
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rmaguire314 at gmail dot com
  Target Milestone: ---

A very short combination of C / C++ files triggers the bug:
https://godbolt.org/z/nq79qe8dM

When __attribute__((always_inline)) inline is used in a C file, which is then
compiled with -O1 -flto -std=c23 (or -O2 or -O3), and then used in a C++ file
(which is compiled with -O1 -flto, or -O2, or -O3), I get:

gcc-17 -std=c23 -O3 -flto -c add.c
g++-17 -O3 -flto -c main.cpp
g++-17 -O3 -flto add.o main.o -o main

------

add.c: In function ‘main’:
add.c:4:8: error: inlining failed in call to ‘always_inline’ ‘add.constprop’:
optimization level attribute mismatch
    4 | double add(const double x, const double y)
      |        ^
main.cpp:11:27: note: called from here
   11 |     const double sum = add(a, b);
      |                           ^
lto-wrapper: fatal error: g++-17 returned 1 exit status
compilation terminated.
/usr/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status

------

With -std=c17 there is no issue.

gcc-17 -std=c17 -O3 -flto -c add.c
g++-17 -O3 -flto -c main.cpp
g++-17 -O3 -flto add.o main.o -o main
./main

------

1.0E+00 + 2.0E+00 = 3.0E+00

------

GCC compiled from source with no edits.
gcc-17 (GCC) 17.0.0 20260526 (experimental)
  • [Bug c/126187] New: C vs. C++ Op... rmaguire314 at gmail dot com via Gcc-bugs

Reply via email to