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

            Bug ID: 105120
           Summary: __OPTIMIZE__ macro incorrectly defined when using
                    pragma(optimize) with push_options/pop_options
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andrey.turkin at gmail dot com
  Target Milestone: ---

Created attachment 52730
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52730&action=edit
Sample code

The code contains a "GCC optimize" pragma and some inline functions which are
supposed to be optimized (that section is surrounded by
push_options/pop_options which is supposed to protect following code from this
pragma) and then some code which is using MMX intrinsics (see attached minified
example). File is compiled with -O0 (or no optimization options at all - so
"gcc sample.c" should suffice to reproduce this).
The code following pop_options pragma should be unaffected by optimize pragma
but it sees __OPTIMIZE__ macro defined even though optimization options are
unaffected; this breaks the build because the source includes intrinsic headers
which use this macro to select between intrinsic implementations.

I put this bug into C component, not sure if that's exactly right. C++ is
affected by this also though it is harder to reproduce. __OPTIMIZE__ is still
incorrectly defined when compiling C++ but we can't see it because of bug 48026
(which makes it seem as if __OPTIMIZE__ is not defined at all). However if we
put that entire push_options/pop_options section, and just it, in a separate
header file and we PCH it then PCH state will still contain __OPTIMIZE__ macro
defined and intrinsic headers will still use wrong implementation and
everything still fails the same way.

I tried gcc 9, 10, 11 and current trunk of 12 and results are the same for all
of them.

Reply via email to