Page MenuHomePhabricator

Fix CLANG_ENABLE_STATIC_ANALYZER=OFF building all analyzer source
ClosedPublic

Authored by arichardson on Sep 10 2021, 10:02 AM.

Details

Summary

Since https://reviews.llvm.org/D87118, the StaticAnalyzer directory is
added unconditionally. In theory this should not cause the static analyzer
sources to be built unless they are referenced by another target. However,
the clang-cpp target (defined in clang/tools/clang-shlib) uses the
CLANG_STATIC_LIBS global property to determine which libraries need to
be included. To solve this issue, this patch avoids adding libraries to
that property if EXCLUDE_FROM_ALL is set.

In case something like this comes up again: cmake --graphviz=targets.dot
is quite useful to see why a target is included as part of ninja all.

Diff Detail

Event Timeline

arichardson created this revision.Sep 10 2021, 10:02 AM
arichardson requested review of this revision.Sep 10 2021, 10:02 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptSep 10 2021, 10:02 AM

Can you just set CLANG_TIDY_ENABLE_STATIC_ANALYZER=OFF too if you care about this?

Can you just set CLANG_TIDY_ENABLE_STATIC_ANALYZER=OFF too if you care about this?

That doesn't have any effect on the libraries linked into clang-shlib. I am not building clang-tools-extra, so that does not make any difference.

thakis accepted this revision.Sep 13 2021, 6:22 AM
This revision is now accepted and ready to land.Sep 13 2021, 6:22 AM

This breaks the build for us:

Running cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON '-DLLVM_ENABLE_PROJECTS=clang;compiler-rt;lld;chrometools;clang-tools-extra' -DLLVM_CHECK_ENABLED_PROJECTS=OFF '-DLLVM_TARGETS_TO_BUILD=AArch64;ARM;Mips;PowerPC;SystemZ;WebAssembly;X86' -DLLVM_ENABLE_PIC=OFF -DLLVM_ENABLE_UNWIND_TABLES=OFF -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_Z3_SOLVER=OFF -DCLANG_PLUGIN_SUPPORT=OFF -DCLANG_ENABLE_STATIC_ANALYZER=OFF -DCLANG_ENABLE_ARCMT=OFF '-DBUG_REPORT_URL=https://crbug.com and run tools/clang/scripts/process_crashreports.py (only works inside Google) which will upload a report' -DLLVM_INCLUDE_GO_TESTS=OFF -DENABLE_X86_RELAX_RELOCATIONS=NO -DLLVM_ENABLE_DIA_SDK=OFF '-DCOMPILER_RT_SANITIZERS_TO_BUILD=asan;dfsan;msan;hwasan;tsan;cfi' -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF -DLLVM_LOCAL_RPATH=/b/s/w/ir/cache/builder/src/third_party/llvm-build-tools/gcc-10.2.0-trusty/lib64 '-DCOMPILER_RT_TEST_COMPILER_CFLAGS=--gcc-toolchain=/b/s/w/ir/cache/builder/src/third_party/llvm-build-tools/gcc-10.2.0-trusty -Wl,-rpath,/b/s/w/ir/cache/builder/src/third_party/llvm-build-tools/gcc-10.2.0-trusty/lib64 -Wl,-rpath,/b/s/w/ir/cache/builder/src/third_party/llvm-build-tools/gcc-10.2.0-trusty/lib32' -DLLVM_ENABLE_LIBXML2=FORCE_ON -DCMAKE_C_COMPILER=/b/s/w/ir/cache/builder/src/third_party/llvm-build-tools/gcc-10.2.0-trusty/bin/gcc -DCMAKE_CXX_COMPILER=/b/s/w/ir/cache/builder/src/third_party/llvm-build-tools/gcc-10.2.0-trusty/bin/g++ -DCOMPILER_RT_BUILD_CRT=OFF -DCOMPILER_RT_BUILD_LIBFUZZER=OFF -DCOMPILER_RT_BUILD_MEMPROF=OFF -DCOMPILER_RT_BUILD_ORC=OFF -DCOMPILER_RT_BUILD_PROFILE=ON -DCOMPILER_RT_BUILD_SANITIZERS=ON -DCOMPILER_RT_BUILD_XRAY=OFF -DCOMPILER_RT_BUILD_BUILTINS=OFF -DCMAKE_C_FLAGS=-DLLVM_FORCE_HEAD_REVISION -DCMAKE_CXX_FLAGS=-DLLVM_FORCE_HEAD_REVISION -DCMAKE_EXE_LINKER_FLAGS= -DCMAKE_SHARED_LINKER_FLAGS= -DCMAKE_MODULE_LINKER_FLAGS= -DCMAKE_INSTALL_PREFIX=/b/s/w/ir/cache/builder/src/third_party/llvm-build/Release+Asserts -DCHROMIUM_TOOLS_SRC=/b/s/w/ir/cache/builder/src/tools/clang '-DCHROMIUM_TOOLS=translation_unit;blink_gc_plugin;plugins' -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-linux-gnu /b/s/w/ir/cache/builder/src/third_party/llvm/llvm


-- Configuring done
CMake Error: install(EXPORT "ClangTargets" ...) includes target "clangTidy" which requires target "clangStaticAnalyzerCore" that is not in any export set.
CMake Error: install(EXPORT "ClangTargets" ...) includes target "clangTidy" which requires target "clangStaticAnalyzerFrontend" that is not in any export set.
CMake Error: install(EXPORT "ClangTargets" ...) includes target "clangTidyMPIModule" which requires target "clangStaticAnalyzerCheckers" that is not in any export set.
CMake Error in /b/s/w/ir/cache/builder/src/third_party/llvm/clang/cmake/modules/CMakeLists.txt:
  export called with target "clangTidy" which requires target
  "clangStaticAnalyzerCore" that is not in any export set.


CMake Error in /b/s/w/ir/cache/builder/src/third_party/llvm/clang/cmake/modules/CMakeLists.txt:
  export called with target "clangTidy" which requires target
  "clangStaticAnalyzerFrontend" that is not in any export set.


CMake Error in /b/s/w/ir/cache/builder/src/third_party/llvm/clang/cmake/modules/CMakeLists.txt:
  export called with target "clangTidyMPIModule" which requires target
  "clangStaticAnalyzerCheckers" that is not in any export set.

Are we holding it wrong?

This breaks the build for us:

Running cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DLLVM_ENABLE_ASSERTIONS=ON '-DLLVM_ENABLE_PROJECTS=clang;compiler-rt;lld;chrometools;clang-tools-extra' -DLLVM_CHECK_ENABLED_PROJECTS=OFF '-DLLVM_TARGETS_TO_BUILD=AArch64;ARM;Mips;PowerPC;SystemZ;WebAssembly;X86' -DLLVM_ENABLE_PIC=OFF -DLLVM_ENABLE_UNWIND_TABLES=OFF -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_Z3_SOLVER=OFF -DCLANG_PLUGIN_SUPPORT=OFF -DCLANG_ENABLE_STATIC_ANALYZER=OFF -DCLANG_ENABLE_ARCMT=OFF '-DBUG_REPORT_URL=https://crbug.com and run tools/clang/scripts/process_crashreports.py (only works inside Google) which will upload a report' -DLLVM_INCLUDE_GO_TESTS=OFF -DENABLE_X86_RELAX_RELOCATIONS=NO -DLLVM_ENABLE_DIA_SDK=OFF '-DCOMPILER_RT_SANITIZERS_TO_BUILD=asan;dfsan;msan;hwasan;tsan;cfi' -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=OFF -DLLVM_LOCAL_RPATH=/b/s/w/ir/cache/builder/src/third_party/llvm-build-tools/gcc-10.2.0-trusty/lib64 '-DCOMPILER_RT_TEST_COMPILER_CFLAGS=--gcc-toolchain=/b/s/w/ir/cache/builder/src/third_party/llvm-build-tools/gcc-10.2.0-trusty -Wl,-rpath,/b/s/w/ir/cache/builder/src/third_party/llvm-build-tools/gcc-10.2.0-trusty/lib64 -Wl,-rpath,/b/s/w/ir/cache/builder/src/third_party/llvm-build-tools/gcc-10.2.0-trusty/lib32' -DLLVM_ENABLE_LIBXML2=FORCE_ON -DCMAKE_C_COMPILER=/b/s/w/ir/cache/builder/src/third_party/llvm-build-tools/gcc-10.2.0-trusty/bin/gcc -DCMAKE_CXX_COMPILER=/b/s/w/ir/cache/builder/src/third_party/llvm-build-tools/gcc-10.2.0-trusty/bin/g++ -DCOMPILER_RT_BUILD_CRT=OFF -DCOMPILER_RT_BUILD_LIBFUZZER=OFF -DCOMPILER_RT_BUILD_MEMPROF=OFF -DCOMPILER_RT_BUILD_ORC=OFF -DCOMPILER_RT_BUILD_PROFILE=ON -DCOMPILER_RT_BUILD_SANITIZERS=ON -DCOMPILER_RT_BUILD_XRAY=OFF -DCOMPILER_RT_BUILD_BUILTINS=OFF -DCMAKE_C_FLAGS=-DLLVM_FORCE_HEAD_REVISION -DCMAKE_CXX_FLAGS=-DLLVM_FORCE_HEAD_REVISION -DCMAKE_EXE_LINKER_FLAGS= -DCMAKE_SHARED_LINKER_FLAGS= -DCMAKE_MODULE_LINKER_FLAGS= -DCMAKE_INSTALL_PREFIX=/b/s/w/ir/cache/builder/src/third_party/llvm-build/Release+Asserts -DCHROMIUM_TOOLS_SRC=/b/s/w/ir/cache/builder/src/tools/clang '-DCHROMIUM_TOOLS=translation_unit;blink_gc_plugin;plugins' -DLLVM_DEFAULT_TARGET_TRIPLE=x86_64-unknown-linux-gnu /b/s/w/ir/cache/builder/src/third_party/llvm/llvm


-- Configuring done
CMake Error: install(EXPORT "ClangTargets" ...) includes target "clangTidy" which requires target "clangStaticAnalyzerCore" that is not in any export set.
CMake Error: install(EXPORT "ClangTargets" ...) includes target "clangTidy" which requires target "clangStaticAnalyzerFrontend" that is not in any export set.
CMake Error: install(EXPORT "ClangTargets" ...) includes target "clangTidyMPIModule" which requires target "clangStaticAnalyzerCheckers" that is not in any export set.
CMake Error in /b/s/w/ir/cache/builder/src/third_party/llvm/clang/cmake/modules/CMakeLists.txt:
  export called with target "clangTidy" which requires target
  "clangStaticAnalyzerCore" that is not in any export set.


CMake Error in /b/s/w/ir/cache/builder/src/third_party/llvm/clang/cmake/modules/CMakeLists.txt:
  export called with target "clangTidy" which requires target
  "clangStaticAnalyzerFrontend" that is not in any export set.


CMake Error in /b/s/w/ir/cache/builder/src/third_party/llvm/clang/cmake/modules/CMakeLists.txt:
  export called with target "clangTidyMPIModule" which requires target
  "clangStaticAnalyzerCheckers" that is not in any export set.

Are we holding it wrong?

Hmm that sounds like it might be awkward to fix. I'll try to look into it ASAP (tomorrow morning UK time). In the mean time feel free to revert if this is a blocker for you.

thakis added a comment.EditedSep 20 2021, 1:19 PM

Thanks, reverted in 9197834535364efff505580ef940ad41cd293275 for now.

Here's a shorter cmake invocation that repros it: cmake -GNinja -DCLANG_ENABLE_STATIC_ANALYZER=OFF ../llvm-project/llvm '-DLLVM_ENABLE_PROJECTS=llvm;clang;clang-tools-extra' -DCLANG_ENABLE_ARCMT=OFF

(i.e. just turn off CLANG_ENABLE_STATIC_ANALYZER but keep CLANG_TIDY_ENABLE_STATIC_ANALYZER on.)