Skip to content

cmake: Windows, adjust compiler identification on compiler swap #40547

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
Dec 15, 2021

Conversation

lxbndr
Copy link
Contributor

@lxbndr lxbndr commented Dec 14, 2021

The latest CMake on Windows doesn't add _CRT_USE_BUILTIN_OFFSETOF flag after we swap the compiler to clang-cl for targets like SourceKit. Also _add_host_variant_c_compile_flags doesn't do so, because compiler identification still points to MSVC compiler.

_CRT_USE_BUILTIN_OFFSETOF flag is necessary for offsetof calls to be accepted as an integral constant expression. Otherwise, SourceKit build fails with the following error:

... \swift\include\swift/SIL/SILInstruction.h(1013,17): error: static_assert expression is not an integral constant expression
  static_assert(offsetof(SingleValueInstruction, Bits) ==
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This patch adjusts compiler identification on compiler swap and also addresses some configuration issues related to clang-cl.

Resolves SR-NNNN.

The latest CMake on Windows doesn't add `_CRT_USE_BUILTIN_OFFSETOF`
flag after we swap the compiler to clang-cl for targets like SourceKit. Also
`_add_host_variant_c_compile_flags` doesn't do so, because compiler
identification still points to MSVC compiler.

`_CRT_USE_BUILTIN_OFFSETOF` flag is necessary for `offsetof` calls to be
accepted as an integral constant expression.

This patch adjusts compiler identification on compiler swap and also
addresses some configuration issues related to clang-cl.
@lxbndr
Copy link
Contributor Author

lxbndr commented Dec 14, 2021

cc @compnerd

@compnerd
Copy link
Member

@swift-ci please test

# Both clang and clang-cl on Windows set CMAKE_C_SIMULATE_ID to MSVC.
# We are using CMAKE_C_COMPILER_FRONTEND_VARIANT to detect the correct
# way to pass -Xclang arguments.
if ("${CMAKE_C_COMPILER_FRONTEND_VARIANT}" STREQUAL "MSVC")
Copy link
Member

Choose a reason for hiding this comment

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

The critical thing to note here is the condition on L559 - we know that the compiler ID is not MSVC, so we are assuming that this is clang (the assumption is reasonable for now as even the Linux path is currently unable to be supported by gcc due to other issues).

@compnerd compnerd merged commit a32396b into swiftlang:main Dec 15, 2021
@lxbndr lxbndr deleted the lxbndr/offsetof branch December 15, 2021 22:00
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.

2 participants