https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104426
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> --- Created attachment 52369 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52369&action=edit gcc12-pr104426.patch Untested fix. This stops the implied setting of -fno-delete-null-pointer-checks for sanitizers and instead introduces an inline function that decides if null pointer checks should be done or not. In initializers and C++ manifestly constant expressions only the -f{,no-}delete-null-pointer-checks from command line or implied from some DSP targets will be honored (and separate question is if automatic vars can be assumed to be non-NULL even on those targets), while outside of those we keep what we've been doing before, i.e. UBSan disables those optimizations so that -fsanitize=null etc. can continue working correctly.