<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/62451>62451</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            `clang-tidy` fails when using MSVC precompiled headers 
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Tolker-KU
      </td>
    </tr>
</table>

<pre>
    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.

```cmake
# 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>)
```

```cpp
// 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
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWVtv2zgW_jXMC0HDlmwnfvCD48tMMElTJGk6sy8GRR7bbChSS1KOsw_z2xckdbObdlqg2VlgChiWeDmH1He-cxFFrRVbBTBFo0s0WpzR0u20mT5o-QSG_PbhLNP8ZTrXaiO2pRFqi5mkakuc4C94Y3SO5zf0CTBVHJfWj9_cP85xYYDpvBASON4B5WAszukT2CNxKiR-Fm6H3Q4wGKMN6i9Qf1b9j_vVLzTjeDrDpaKZBOw03lHFJeC4EnVCK5TMMRwKYA44hgNlTr5greo5YPAnnWGhcLVEco5RksxROkOjORrN3xu9NTTHKyHBxq4bwYy2euPwo7AllfjelVzoOJj0k6SR3IC1QisqY8_jPF4ftJaVrmu5z-PdYTyMN5lQ8aYCRmuJkqTeXkIYG6Ak8bskzohCQtU6XIzX4yEpGHkWiutnS3K7Z4NJLx320sFkOKylNvZFOXogWsmXuo8L6zEkGwO1PsIkUEOodSSDjTZAMsqeQPGj3dSCUu5zsgcjNgJMRyujhpM9lSUQRXOw9VBOhSIbIWN31cs8I9YF2_XY4dDMNCA1C8YkueYgq4FCsHpKIRiRsG-GkqMt5htDcyCFFsqBQelCadU8pAFJD8AJlYJ6tjYg5dTtCBijdNO1KQjTyhnKHEoXnlvVgNLE6FJxobbEyzVbZ1pZZ0rmtIkrVAA0e9uUyluLOA-iRekiaWxLzRYcYUXZ2peMGyPmHvC64YeozUk0LEoX_kllo6lU0NGzBQWmxW6xXiwvP_zSNm8eOkPX10dQEg4FKA7KESkylC48xYzjtcRn41ryI7NbR9kTKYx24EHp2KtC3ZK99p7b0JpsuKBbpa0TzJKNNjl11ZBf_BjOrdKEaVnmigi1aSy3ZZrDXsBzQ0zIym2YQp6E4ihddCx1YiGm92DoFkgnqhAuPJHaMBEUrsOaoa1LV3lzKSRvPDwufLyAAatLwyDojPv7O8OPt1sbfuLtYNTr9wbH2w4P5glf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