Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(MSVC): Don't enforce /Zi if POLICY CMP0141 is available #264

Merged
merged 1 commit into from
Aug 12, 2024

Conversation

ddassie-texa
Copy link
Contributor

@ddassie-texa ddassie-texa commented Jun 17, 2024

With the current implementation if CMAKE_MSVC_DEBUG_INFORMATION_FORMAT is set, it won't be respected as the /Zi flag set on enable_sanitizers will always override it, just skip setting it if POLICY CMP0141 is available, if the user has set CMAKE_MSVC_DEBUG_INFORMATION_FORMAT to EditAndContinue, than only in that case override it.

Fixes #262

Comment on lines -90 to +101
${_project_name} INTERFACE /fsanitize=${LIST_OF_SANITIZERS} /Zi /INCREMENTAL:NO
${_project_name} INTERFACE /fsanitize=${LIST_OF_SANITIZERS} /INCREMENTAL:NO
Copy link
Owner

Choose a reason for hiding this comment

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

Would this break the default sanitizer experience? We want the sanitizer to work by default in MSVC.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think so, from version 3.25 CMake sets MSVC_DEBUG_INFORMATION_FORMAT to $<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>, (see: https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_DEBUG_INFORMATION_FORMAT.html) it might break for Release/MinSizeRel builds as no debug info is generated by default.
We could set MSVC_DEBUG_INFORMATION_FORMAT to ProgramDatabase unconditionally, users can still override it in their own targets, but if they have explicitly set CMAKE_MSVC_DEBUG_INFORMATION_FORMAT to a compatible value we should not override it.

Copy link
Owner

@aminya aminya Jun 20, 2024

Choose a reason for hiding this comment

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

I just want to make sure we don't have a regression in the default experience, i.e., the address sanitizer should work by default. So as long as that's the case, this change should be OK.

@ddassie-texa ddassie-texa force-pushed the feature/msvc-debug-format-fix branch from 9d44192 to 3262a39 Compare June 18, 2024 06:15
With the current implementation if CMAKE_MSVC_DEBUG_INFORMATION_FORMAT is set,
it won't be respected as the /Zi flag is always set in enable_sanitizers.

If POLICY CMP0141 is available, don't set the /Zi flag,
instead use MSVC_DEBUG_INFORMATION_FORMAT, if the user didn't set
CMAKE_MSVC_DEBUG_INFORMATION_FORMAT or set it to EditAndContinue,
than only in that case set it to ProgramDatabase.
@ddassie-texa ddassie-texa force-pushed the feature/msvc-debug-format-fix branch from 3262a39 to 398f901 Compare June 18, 2024 06:37
@aminya aminya merged commit 415c877 into aminya:main Aug 12, 2024
19 of 20 checks passed
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.

Enabling Address Sanitizer overrides the debug format on MSVC
2 participants