fmt uses a scoped optimization pragma in include/fmt/base.h:
FMT_PRAGMA_GCC(push_options)
#if !defined(__OPTIMIZE__) && !defined(__CUDACC__) && !defined(FMT_MODULE)
FMT_PRAGMA_GCC(optimize("Og"))
#endif
...
FMT_PRAGMA_GCC(pop_options)
This is correct in normal compilation. However, with GCC + PCH, this can leave the compiler in an inconsistent state after PCH restore and break unrelated code.
Example failure:
error: the last argument must be an 8-bit immediate
from _mm_srli_si128(x, 2) in <emmintrin.h>.
The same code compiles fine without PCH.
Related Bugs
I originally reported as GCC bug(RHBZ 2457604): https://bugzilla.redhat.com/show_bug.cgi?id=2457604
Also similar bug report in GCC bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105120
Similar bug report suggest that #pragma GCC optimize state is not fully or consistently restored across PCH boundaries.
Workarounds
Current options are:
- avoid using PCH with affected GCC versions
- avoid affected GCC versions
Proposed Workaround in fmt
Please add an opt-out macro to disable the optimization pragma:
#if !defined(FMT_DISABLE_DEBUG_OPTIMIZE_PRAGMA)
FMT_PRAGMA_GCC(push_options)
#if !defined(__OPTIMIZE__) && !defined(__CUDACC__) && !defined(FMT_MODULE)
FMT_PRAGMA_GCC(optimize("Og"))
#endif
#endif // !defined(FMT_DISABLE_DEBUG_OPTIMIZE_PRAGMA)
...
#if !defined(FMT_DISABLE_DEBUG_OPTIMIZE_PRAGMA)
FMT_PRAGMA_GCC(pop_options)
#endif // !defined(FMT_DISABLE_DEBUG_OPTIMIZE_PRAGMA)
Rationale
- This is a QoI/debug optimization, not required for correctness
- Default behavior remains unchanged
- Provides a reliable escape hatch for GCC + PCH users
- Avoids forcing users to drop PCH or fmt usage
fmtuses a scoped optimization pragma in include/fmt/base.h:This is correct in normal compilation. However, with GCC + PCH, this can leave the compiler in an inconsistent state after PCH restore and break unrelated code.
Example failure:
error: the last argument must be an 8-bit immediatefrom
_mm_srli_si128(x, 2) in<emmintrin.h>.The same code compiles fine without PCH.
Related Bugs
I originally reported as GCC bug(RHBZ 2457604): https://bugzilla.redhat.com/show_bug.cgi?id=2457604
Also similar bug report in GCC bugzilla: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105120
Similar bug report suggest that #pragma GCC optimize state is not fully or consistently restored across PCH boundaries.
Workarounds
Current options are:
Proposed Workaround in
fmtPlease add an opt-out macro to disable the optimization pragma:
Rationale