https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107071
--- Comment #10 from Richard Earnshaw <rearnsha at gcc dot gnu.org> --- That sounds broadly sensible. One optimization might be to check if the exception trapping is already enabled, then you can skip the read/set/restore dance entirely in that case. That might be more efficient on some hardware as changing the flags might cause a pipeline bubble. The same is also true for the other tests where you do a read/set/restore sequence.