public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/105120] New: __OPTIMIZE__ macro incorrectly defined when using pragma(optimize) with push_options/pop_options
@ 2022-04-01 6:38 andrey.turkin at gmail dot com
2022-04-01 7:01 ` [Bug c/105120] " rguenth at gcc dot gnu.org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: andrey.turkin at gmail dot com @ 2022-04-01 6:38 UTC (permalink / raw)
To: gcc-bugs
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.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/105120] __OPTIMIZE__ macro incorrectly defined when using pragma(optimize) with push_options/pop_options
2022-04-01 6:38 [Bug c/105120] New: __OPTIMIZE__ macro incorrectly defined when using pragma(optimize) with push_options/pop_options andrey.turkin at gmail dot com
@ 2022-04-01 7:01 ` rguenth at gcc dot gnu.org
2022-04-01 7:15 ` rguenth at gcc dot gnu.org
2022-04-01 7:33 ` andrey.turkin at gmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-01 7:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105120
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Ever confirmed|0 |1
Status|UNCONFIRMED |NEW
Keywords| |wrong-code
Last reconfirmed| |2022-04-01
--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
This is known and hard to fix - it also applies to other macros whose
definition depends on optimization flags (like from -ffast-math). When you run
into such
issue the workaround is to split the translation units at optimization flag
boundary.
It's odd that we manage to sneak in __OPTIMIZE__, I didn't know we do. Same
applies to -ffast-math it seems:
_Pragma("GCC push_options")
#ifndef __FAST_MATH__
_Pragma("GCC optimize(\"fast-math\")")
#endif
inline void noop() {}
_Pragma ("GCC pop_options")
#ifdef __FAST_MATH__
#pragma message("__FAST_MATH__ defined")
#endif
so pop_options fails to pop the macro definitions.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/105120] __OPTIMIZE__ macro incorrectly defined when using pragma(optimize) with push_options/pop_options
2022-04-01 6:38 [Bug c/105120] New: __OPTIMIZE__ macro incorrectly defined when using pragma(optimize) with push_options/pop_options andrey.turkin at gmail dot com
2022-04-01 7:01 ` [Bug c/105120] " rguenth at gcc dot gnu.org
@ 2022-04-01 7:15 ` rguenth at gcc dot gnu.org
2022-04-01 7:33 ` andrey.turkin at gmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-04-01 7:15 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105120
--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
c_cpp_builtins_optimize_pragma does the macro adjustment, but in
handle_pragma_pop_options it doesn't get called because the guarding condition
if (p->optimize_binary != optimization_current_node)
is false.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c/105120] __OPTIMIZE__ macro incorrectly defined when using pragma(optimize) with push_options/pop_options
2022-04-01 6:38 [Bug c/105120] New: __OPTIMIZE__ macro incorrectly defined when using pragma(optimize) with push_options/pop_options andrey.turkin at gmail dot com
2022-04-01 7:01 ` [Bug c/105120] " rguenth at gcc dot gnu.org
2022-04-01 7:15 ` rguenth at gcc dot gnu.org
@ 2022-04-01 7:33 ` andrey.turkin at gmail dot com
2 siblings, 0 replies; 4+ messages in thread
From: andrey.turkin at gmail dot com @ 2022-04-01 7:33 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105120
--- Comment #3 from Andrey Turkin <andrey.turkin at gmail dot com> ---
Personally I don't care much about implications of bug 48026; the issue that
affects me is pop_options leaking some state changed by pragmas inside
push_options/pop_options, namely macros. That sample was derived from a
real-world example there we use a third-party library (fmt) which does this
optimize thing in its core header - it defines a number of inline functions and
supposedly the optimize makes resulting debug binaries smaller (not sure how
optimize override works with regard to inline functions but they must've done
this for a reason); that library is included into our logging header which is
used pretty much everywhere, and it is PCHed. Which means that we are getting
inconsistent compiler state everywhere in a debug build, and there is no way to
separate it into its own TU.
I think pop_options should roll back these compiler-defined macros; in the
meantime there is a workaround - one can explicitely wrap such
push_options/pop_options block with push_macro("__OPTIMIZE__")/pop_macro pair.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-04-01 7:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-01 6:38 [Bug c/105120] New: __OPTIMIZE__ macro incorrectly defined when using pragma(optimize) with push_options/pop_options andrey.turkin at gmail dot com
2022-04-01 7:01 ` [Bug c/105120] " rguenth at gcc dot gnu.org
2022-04-01 7:15 ` rguenth at gcc dot gnu.org
2022-04-01 7:33 ` andrey.turkin at gmail dot com
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).