Skip to content
/ server Public

MDEV-39086 MSAN/UBSAN/ASAN builds run without basic optimization (fix)#4818

Open
grooverdan wants to merge 1 commit intoMariaDB:10.6from
grooverdan:MDEV-39086
Open

MDEV-39086 MSAN/UBSAN/ASAN builds run without basic optimization (fix)#4818
grooverdan wants to merge 1 commit intoMariaDB:10.6from
grooverdan:MDEV-39086

Conversation

@grooverdan
Copy link
Member

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.

@grooverdan grooverdan requested a review from vaintroub March 17, 2026 22:25
@grooverdan grooverdan added the MariaDB Foundation Pull requests created by MariaDB Foundation label Mar 17, 2026
Copy link
Member

@vaintroub vaintroub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@grooverdan
Copy link
Member Author

Thanks @vaintroub , updated with your recommendation and tested it. It looks very good. Feel free to merge or request improved descriptions.

@grooverdan grooverdan requested a review from vaintroub March 23, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MariaDB Foundation Pull requests created by MariaDB Foundation

Development

Successfully merging this pull request may close these issues.

2 participants