Skip to content

Add a workaround for Windows ARM64 miscompile #816

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

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,24 @@ else()
target_compile_options(dispatch PRIVATE -Wall)
endif()

# Work around a release-mode miscompile on windows arm64
# Disable /Os and /Ot in /O1 and /O2 on queue.c
if(("${CMAKE_C_SIMULATE_ID}" STREQUAL "MSVC") AND
(("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ARM64") OR
("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")))
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
set(FLAGS_BUILD_TYPE "${CMAKE_C_FLAGS_${uppercase_CMAKE_BUILD_TYPE}}")
string(REGEX MATCHALL "/[Oo][12]" FLAGS "${CMAKE_C_FLAGS} ${FLAGS_BUILD_TYPE}")
if (FLAGS)
if (FLAGS MATCHES "1$")
set(FLAGS "/Od;/Og;/Oy;/Ob2;/GF;/Gy")
elseif (FLAGS MATCHES "2$")
set(FLAGS "/Od;/Og;/Oi;/Oy;/Ob2;/GF;/Gy")
endif()
set_source_files_properties(queue.c PROPERTIES COMPILE_OPTIONS "${FLAGS}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do this through #pragma's that disable optimizations in the source file instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could but the pragma just disables all optimizations and cannot selectively choose the opt flags (though it'd allow to narrow down by functions.) Pros and cons, but I think this is preferred as it doesn't disable all the optimizations.

endif()
endif()
Copy link
Member

Choose a reason for hiding this comment

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

Wow, this is ... ugly. I can't think of a better way to write this though.


# FIXME(compnerd) add check for -fblocks?
target_compile_options(dispatch PRIVATE -fblocks)

Expand Down