Skip to content

Block optimize pragma on EDG - #4980

Merged
vitaut merged 1 commit into
fmtlib:mainfrom
ilazaric:ilazaric/edg
Oct 11, 2026
Merged

vitaut merged 1 commit into
fmtlib:mainfrom
ilazaric:ilazaric/edg

Conversation

@ilazaric

@ilazaric ilazaric commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

EDG over GCC likes to pretend to be GCC in a lot of macros, but not all.
It does not define __OPTIMIZE__ ever.
So we would erroneously emit pragma optimize Og even in optimized builds.

EDG over GCC likes to pretend to be GCC in a lot of macros,
but not all. It does not define `__OPTIMIZE__` ever.
So we would erroneously emit pragma optimize `Og`
even in optimized builds.
@ilazaric
ilazaric requested a review from vitaut as a code owner October 9, 2026 03:54
@vitaut

vitaut commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Is emitting a pragma actually harmful on EDG? Could you elaborate what exactly happens in the optimized mode?

@ilazaric

Copy link
Copy Markdown
Contributor Author

Not from EDG perspective, but yes from GCC perspective.
EDG consumes C++ and generates C code, which is compiled with GCC.
The pragma optimize is just passed through, so if you were wanting a O2 build,
you're instead getting a Og build, pretty bad in most contexts.

But until recently there was an even worse situation.
When GCC -O2 would hit the pragma optimize,
it wouldn't really switch all options to what Og does,
the relevant part is it would become -Og -fipa-icf-functions build.
And EDG would emit certain kind of C code that runs into a GCC bug:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127703

But it seems something changed in EDG since then,
couldn't get trunk to reproduce running into this bug,
and all you run into is unexpected horrible performance :)

@ilazaric

Copy link
Copy Markdown
Contributor Author

Example on EDG 7: https://godbolt.org/z/jh5zhT3Kh

@vitaut
vitaut merged commit b4ffa39 into fmtlib:main Oct 11, 2026
47 checks passed
@vitaut

vitaut commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants