MDEV-39086 MSAN/UBSAN/ASAN builds run without basic optimization (fix)#4818
Open
grooverdan wants to merge 1 commit intoMariaDB:10.6from
Open
MDEV-39086 MSAN/UBSAN/ASAN builds run without basic optimization (fix)#4818grooverdan wants to merge 1 commit intoMariaDB:10.6from
grooverdan wants to merge 1 commit intoMariaDB:10.6from
Conversation
vaintroub
requested changes
Mar 19, 2026
Member
There was a problem hiding this comment.
I have thought about it a bit, and I think the best way to express what you like to express is
IF(CMAKE_CXX_COMPILER_ID MATCHES "(GNU|Clang|AppleClang)"
AND (WITH_ASAN OR WITH_UBSAN OR WITH_MSAN))
SET(_all_lang_flags " ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}")
IF(NOT _all_lang_flags MATCHES " -O[0-9sgzf]")
ADD_COMPILE_OPTIONS($<$<CONFIG:Debug>:-Og>)
ENDIF()
ENDIF()Explanation
- restrict to compilers you know and care about (MSVC btw also has -Og but those are very aggressive optimizations)
- only add this -Og to Debug configuration, and only if no optimization flags are set
- Do it is a way that works with multi-config generators such as Xcode or Ninja Multiconfig (I exclude VS here, since it is irrelevant for the change, but others are not irrelevant)
- "modern" (i.e not older that 3.0 CMake) add_compiler_options. No need to check and set . You know the compilers you care about.
Your change, as-is, would not work with multi-config, in fact it would -Og with all configurations of multi-config generator
Change to an inclusive set that actually supports the -Og compiler option. By using ADD_COMPILE_OPTIONS we can support multi-config generators of CMake and restrict change to only the Debug CMAKE_BUILD_TYPE.
Member
Author
|
Thanks @vaintroub , updated with your recommendation and tested it. It looks very good. Feel free to merge or request improved descriptions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As noted the MSVC supports a different range of optimization flags and therefore not setting -Og.
When CMAKE_BUILD_TYPE is specified its in a mixed case, but the CMAKE_C{,XX}FLAGS${BUILD_TYPE} is always upper case.