This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Check for problematic MSVC + /arch:AVX configuration
ClosedPublic

Authored by thieta on Apr 14 2022, 3:23 AM.

Details

Summary

Add a new CMake file to expand on for more problematic configurations
in the future.

Related to #54645

Diff Detail

Event Timeline

thieta created this revision.Apr 14 2022, 3:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2022, 3:23 AM
Herald added a subscriber: mgorny. · View Herald Transcript
thieta requested review of this revision.Apr 14 2022, 3:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 14 2022, 3:23 AM

Ping on this one - any thoughts?

I'd like this to go in as we have so little control over the MSVC crash (and have struggled to even reduce the repro), but I'm not an expert on cmake or llvm's cmake style

beanz accepted this revision.Apr 20 2022, 8:18 AM
beanz added reviewers: compnerd, phosek, smeenai.
beanz added subscribers: smeenai, phosek, compnerd.

This looks good to me and seems like a good added check.

@compnerd, @phosek or @smeenai may have thoughts too.

This revision is now accepted and ready to land.Apr 20 2022, 8:18 AM

LGTM!

llvm/cmake/modules/CheckProblematicConfigurations.cmake
2

Maybe "allow" would be better than "force"? "force" kinda sounds like the build system will purposely use a problematic toolchain configuration if you turn the flag on.

17

Might be nice to reference the bug URL in the message as well.

smeenai accepted this revision.Apr 20 2022, 9:53 PM
phosek accepted this revision.Apr 20 2022, 9:54 PM

LGTM

llvm/cmake/modules/CheckProblematicConfigurations.cmake
4

We usually use lower_case for the names of functions and macros.

thieta updated this revision to Diff 424114.Apr 21 2022, 12:46 AM

Review fixes

thieta marked 3 inline comments as done.Apr 21 2022, 12:46 AM
This revision was landed with ongoing or failed builds.Apr 21 2022, 12:46 AM
This revision was automatically updated to reflect the committed changes.
thakis added a subscriber: thakis.Aug 19 2022, 4:05 PM

In case it helps anyone in the future:

I ran

% /Applications/CMake.app/Contents/bin/cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_ENABLE_PROJECTS='clang;lld' -DLLVM_ENABLE_RUNTIMES='compiler-rt' -DLLVM_APPEND_VC_REV=NO -DLLVM_TARGETS_TO_BUILD='X86' ../llvm-project/llvm

followed by

% ninja runtimes

<y build eventually failed with:

...
[2736/2740] Performing configure step for 'runtimes'
-- Linker detection: ld64
CMake Error at /Users/thakis/src/llvm-project/llvm/cmake/modules/CheckProblematicConfigurations.cmake:14 (if):
  if given arguments:

    "STREQUAL" "MSVC"

  Unknown arguments specified
Call Stack (most recent call first):
  /Users/thakis/src/llvm-project/llvm/cmake/modules/HandleLLVMOptions.cmake:10 (include)
  CMakeLists.txt:149 (include)

That error went away with the obvious patch [1], but then things failed later like so:

CMake Error at /Users/thakis/src/llvm-project/compiler-rt/CMakeLists.txt:450 (message):
  -g is not supported by host compiler

The problem was that I'm on an arm64 system but didn't include AArch64 in LLVM_TARGETS_TO_BUILD, so runtimes/runtimes-bins/CMakeFiles/CMakeError.log ended up with lots of error: unable to create target: 'No available targets are compatible with triple "arm64-apple-macosx12.0.0"'.

The fix, of course, was to add both ARM and AArch64 to LLVM_TARGETS_TO_BUILD in addition to X86 (-DLLVM_TARGETS_TO_BUILD='X86;ARM;AArch64'), and clobbering the "runtimes" dir in the build dir so that cmake picks it up.

(Adding just AArch64 lead to error: unable to create target: 'No available targets are compatible with triple "thumbv7em-apple-unknown-macho"').

1:

% git diff
diff --git a/llvm/cmake/modules/CheckProblematicConfigurations.cmake b/llvm/cmake/modules/CheckProblematicConfigurations.cmake
index e133873d756c..71484172cfb6 100644
--- a/llvm/cmake/modules/CheckProblematicConfigurations.cmake
+++ b/llvm/cmake/modules/CheckProblematicConfigurations.cmake
@@ -11,7 +11,7 @@ endmacro()
 
 # MSVC and /arch:AVX is untested and have created problems before. See:
 # https://github.com/llvm/llvm-project/issues/54645
-if(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
+if("${CMAKE_CXX_COMPILER_ID}" STREQUAL MSVC)
   string(TOLOWER "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS}" _FLAGS)
   if(_FLAGS MATCHES "/arch:avx[0-9]*")
     log_problematic("Compiling LLVM with MSVC and the /arch:AVX flag is known to cause issues with parts of LLVM.\nSee https://github.com/llvm/llvm-project/issues/54645 for details.\nUse clang-cl if you want to enable AVX instructions.")

(Posting this here since the first symptom of my mistake led me to this patch. It's innocent, but it's where I looked first, so maybe this helps someone else.)