Skip to content

clang-tidy fails when using MSVC precompiled headers Β #62451

@Tolker-KU

Description

@Tolker-KU

Configuring Clang-Tidy from CMake and using MSVC precompiled headers makes Clang-Tidy fail with the error

error: unable to handle compilation, expected exactly one compiler job in 
' "C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\VC\\Tools\\Llvm\\x64\\bin\\clang-tool"
"-cc1" "-triple" "x86_64-pc-windows-msvc19.34.31944" "-fsyntax-only" "-disable-free" "-clear-ast-before-backend"
"-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "cmake_pch.cxx" "-mrelocation-model" "pic" "-pic-level" "2"
"-mframe-pointer=none" "-relaxed-aliasing" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" 
"-funwind-tables=2" "-target-cpu" "x86-64" "-mllvm" "-x86-asm-syntax=intel" "-tune-cpu" "generic" "-D_DEBUG" "-D_MT" "-D_DLL"
"--dependent-lib=msvcrtd" "--dependent-lib=oldnames" "-stack-protector" "2" "-fms-volatile" "-fdiagnostics-format" "msvc" 
"-gno-column-info" "-gcodeview" "-debug-info-kind=constructor" 
"-fcoverage-compilation-dir=C:\\debug_info\\out\\build\\x64-debug" 
"-resource-dir" "C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\VC\\Tools\\Llvm\\x64\\lib\\clang\\15.0.1" 
"-building-pch-with-obj" "-fpch-instantiate-templates" 
"-pch-through-header=C:/debug_info/out/build/x64-debug/CMakeFiles/debug_info.dir/cmake_pch.hxx" 
"-include" "C:/debug_info/out/build/x64-debug/CMakeFiles/debug_info.dir/cmake_pch.hxx" 
"-fdeprecated-macro" "-fdebug-compilation-dir=C:\\debug_info\\out\\build\\x64-debug" "-ferror-limit" "19"
"-fno-use-cxa-atexit" "-fms-extensions" "-fms-compatibility" "-fms-compatibility-version=19.34.31944" 
"-std=c++14" "-fdelayed-template-parsing" "-faddrsig" 
"-x" "c++-header" "C:\\debug_info\\out\\build\\x64-debug\\CMakeFiles\\debug_info.dir\\cmake_pch.cxx";

"C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\VC\\Tools\\Llvm\\x64\\bin\\clang-tool"
"-cc1" "-triple" "x86_64-pc-windows-msvc19.34.31944" "-fsyntax-only" "-disable-free" "-clear-ast-before-backend"
"-disable-llvm-verifier" "-discard-value-names" "-main-file-name" "cmake_pch.cxx" "-mrelocation-model" "pic" "-pic-level" "2"
"-mframe-pointer=none" "-relaxed-aliasing" "-fmath-errno" "-ffp-contract=on" "-fno-rounding-math" "-mconstructor-aliases" 
"-funwind-tables=2" "-target-cpu" "x86-64" "-mllvm" "-x86-asm-syntax=intel" "-tune-cpu" "generic" "-mllvm"
"-treat-scalable-fixed-error-as-warning" "-D_DEBUG" "-D_MT" "-D_DLL" "--dependent-lib=msvcrtd" "--dependent-lib=oldnames"
"-stack-protector" "2" "-fms-volatile" "-fdiagnostics-format" "msvc" "-gno-column-info" "-gcodeview" 
"-debug-info-kind=constructor" "-fcoverage-compilation-dir=C:\\debug_info\\out\\build\\x64-debug" "-resource-dir"
"C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\VC\\Tools\\Llvm\\x64\\lib\\clang\\15.0.1" 
"-building-pch-with-obj" "-fpch-instantiate-templates" 
"-include-pch" "C:debug_info/out/build/x64-debug/CMakeFiles/debug_info.dir/cmake_pch.pch" 
"-pch-through-header=C:/debug_info/out/build/x64-debug/CMakeFiles/debug_info.dir/cmake_pch.hxx" 
"-include" "C:/debug_info/out/build/x64-debug/CMakeFiles/debug_info.dir/cmake_pch.hxx" 
"-fdeprecated-macro" "-fdebug-compilation-dir=C:\\debug_info\\out\\build\\x64-debug" "-ferror-limit" "19"
"-fno-use-cxa-atexit" "-fms-extensions" "-fms-compatibility" "-fms-compatibility-version=19.34.31944" "-std=c++14" 
"-fdelayed-template-parsing" "-faddrsig"
"-x" "c++" "C:\\debug_info\\out\\build\\x64-debug\\CMakeFiles\\debug_info.dir\\cmake_pch.cxx"; ' [clang-diagnostic-error]

when compiling the precompiled header. The above error is produced by the below invocation

"C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin\cmake.exe"
-E __run_co_compile --tidy=clang-tidy;--extra-arg-before=--driver-mode=cl 
--source=C:\debug_info\out\build\x64-debug\CMakeFiles\debug_info.dir\cmake_pch.cxx --
C:\PROGRA~1\MIB055~1\2022\PROFES~1\VC\Tools\MSVC\1434~1.319\bin\Hostx64\x64\cl.exe
/nologo /TP /DWIN32 /D_WINDOWS /EHsc /Ob0 /Od /RTC1 -MDd -Zi 
/YcC:/debug_info/out/build/x64-debug/CMakeFiles/debug_info.dir/cmake_pch.hxx
/FpC:/debug_info/out/build/x64-debug/CMakeFiles/debug_info.dir/./cmake_pch.cxx.pch
/FIC:/debug_info/out/build/x64-debug/CMakeFiles/debug_info.dir/cmake_pch.hxx 
/showIncludes 
/FoCMakeFiles\debug_info.dir\cmake_pch.cxx.obj 
/FdCMakeFiles\debug_info.dir\ 
/FS 
-c C:\debug_info\out\build\x64-debug\CMakeFiles\debug_info.dir\cmake_pch.cxx

The build completes with both cl.exe and clang-cl.exe when disabling Clang-Tidy.

# CMakeLists.txt
cmake_minimum_required(VERSION 3.25)

project(debug_info)

set(CMAKE_CXX_CLANG_TIDY clang-tidy)

add_executable(debug_info main.cpp)
target_precompile_headers(debug_info PRIVATE <iostream>)
// main.cpp
#include <iostream>

int main() {
    std::cout << "Hello, World!\n";
    return 0;
}
> clang-tidy --version
LLVM (http://llvm.org/):
  LLVM version 15.0.1
  Optimized build.
  Default target: x86_64-pc-windows-msvc
  Host CPU: skylake

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions