llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.31k stars 12.11k forks source link

[clang-tidy] Crash while parsing MSVC 2022 STL thread header #98823

Open mikedld opened 4 months ago

mikedld commented 4 months ago

Building with GitHub Actions and using preinstalled clang-tidy:

LLVM (http://llvm.org/):
  LLVM version 18.1.6
  Optimized build.

While processing this file: https://github.com/transmission/transmission/blob/e334f3c37f412b80a23d9d158eff5caa8b3ef04c/libtransmission/session-thread.cc#L104-L108, getting:

[101/136] Building CXX object libtransmission\CMakeFiles\transmission.dir\session-thread.cc.obj
FAILED: libtransmission/CMakeFiles/transmission.dir/session-thread.cc.obj 
"C:\Program Files\CMake\bin\cmake.exe" -E __run_co_compile --tidy="C:/Program Files/LLVM/bin/clang-tidy.exe;--extra-arg-before=--driver-mode=cl" --source=D:\a\transmission\transmission\src\libtransmission\session-thread.cc -- C:\PROGRA~1\MICROS~2\2022\ENTERP~1\VC\Tools\MSVC\1440~1.338\bin\Hostx64\x64\cl.exe  /nologo /TP -DFMT_EXCEPTIONS=0 -DFMT_HEADER_ONLY=1 -DMINIUPNP_STATICLIB -DNATPMP_STATICLIB -DPACKAGE_DATA_DIR="\"C:/Program Files (x86)/transmission/share\"" -DRAPIDJSON_HAS_STDSTRING=1 -DSMALL_DISABLE_EXCEPTIONS=1 -DWIDE_INTEGER_DISABLE_FLOAT_INTEROP -DWIDE_INTEGER_DISABLE_IOSTREAM -DWIN32 -DWITH_OPENSSL -DWITH_UTP -D__TRANSMISSION__ -ID:\a\transmission\transmission\src\libtransmission\.. -ID:\a\transmission\transmission\obj\libtransmission\.. -ID:\a\transmission\transmission\src\third-party\libutp\include -ID:\a\transmission\transmission\src\third-party\libb64\include -ID:\a\transmission\transmission\src\third-party\wildmat -external:ID:\a\transmission\transmission\obj\third-party\libdeflate.bld\pfx\include -external:ID:\x64-prefix\include -external:ID:\a\transmission\transmission\src\third-party\fast_float\include -external:ID:\a\transmission\transmission\obj\third-party\libpsl.bld\pfx\include -external:ID:\a\transmission\transmission\obj\third-party\libnatpmp.bld\pfx\include -external:ID:\a\transmission\transmission\obj\third-party\miniupnp\miniupnpc.bld\pfx\include -external:ID:\a\transmission\transmission\obj\third-party\dht.bld\pfx\include -external:ID:\a\transmission\transmission\src\third-party\rapidjson\include -external:ID:\a\transmission\transmission\src\third-party\utfcpp\source -external:ID:\a\transmission\transmission\src\third-party\wide-integer -external:ID:\a\transmission\transmission\src\third-party\fmt\include -external:ID:\a\transmission\transmission\src\third-party\small\include -external:ID:\a\transmission\transmission\obj\third-party\libevent.bld\pfx\include -external:W0 /DWIN32 /D_WINDOWS /GR /EHsc -DWIN32 -DWINVER=0x0600 -D_WIN32_WINNT=0x0600 -DUNICODE -D_UNICODE -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS /utf-8 /wd4244 /wd4267 -DWIN32_LEAN_AND_MEAN -DNOMINMAX /MDd -Z7 /Ob0 /Od /RTC1 -std:c++17 /W4 /showIncludes /Folibtransmission\CMakeFiles\transmission.dir\session-thread.cc.obj /Fdlibtransmission\CMakeFiles\transmission.dir\transmission.pdb /FS -c D:\a\transmission\transmission\src\libtransmission\session-thread.cc
Error running 'C:/Program Files/LLVM/bin/clang-tidy.exe': PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
1.  <eof> parser at end of file
2.  While analyzing stack: 
    #0 Calling std::thread::id::id(_Thrd_id_t) at line C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.40.33807\include\thread:252:12
    #1 Calling std::this_thread::get_id() at line 106
    #2 Calling (anonymous namespace)::tr_evthread_init_helpers::thread_current_id()
3.  C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\MSVC\14.40.33807\include\thread:230:50: Error evaluating initializer
Exception Code: 0xC0000005
 #0 0x00007ff7b7bf75b9 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x20e75b9)
 #1 0x00007ff7b7968e33 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x1e58e33)
 #2 0x00007ff7b7968d55 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x1e58d55)
 #3 0x00007ff7b796c3fd (C:\Program Files\LLVM\bin\clang-tidy.exe+0x1e5c3fd)
 #4 0x00007ff7b6f87a90 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x1477a90)
 #5 0x00007ff7b6f97f17 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x1487f17)
 #6 0x00007ff7b6f94b21 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x1484b21)
 #7 0x00007ff7b6f93f75 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x1483f75)
 #8 0x00007ff7b6fa7830 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x1497830)
 #9 0x00007ff7b6fa6abc (C:\Program Files\LLVM\bin\clang-tidy.exe+0x1496abc)
#10 0x00007ff7b6d72291 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x1262291)
#11 0x00007ff7b6d667ea (C:\Program Files\LLVM\bin\clang-tidy.exe+0x12567ea)
#12 0x00007ff7b6d79993 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x1269993)
#13 0x00007ff7b68178b8 (C:\Program Files\LLVM\bin\clang-tidy.exe+0xd078b8)
#14 0x00007ff7b5b2d981 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x1d981)
#15 0x00007ff7b5b2d3f2 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x1d3f2)
#16 0x00007ff7b600e197 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x4fe197)
#17 0x00007ff7b5e8a8f5 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x37a8f5)
#18 0x00007ff7b600e035 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x4fe035)
#19 0x00007ff7b600ce7b (C:\Program Files\LLVM\bin\clang-tidy.exe+0x4fce7b)
#20 0x00007ff7b600f72c (C:\Program Files\LLVM\bin\clang-tidy.exe+0x4ff72c)
#21 0x00007ff7b5e86759 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x376759)
#22 0x00007ff7b5e511b1 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x3411b1)
#23 0x00007ff7b6ca9bd0 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x1199bd0)
#24 0x00007ffdf25c4cb0 (C:\Windows\System32\KERNEL32.DLL+0x14cb0)
#25 0x00007ffdf437eceb (C:\Windows\SYSTEM32\ntdll.dll+0x7eceb)
Access violation
PiotrZSL commented 4 months ago

Does it work with clang itself ?

mikedld commented 4 months ago

With CMAKE_CXX_COMPILER=clang-cl (and clang-tidy turned off) the build succeeds.

Snezhnaya-chan commented 3 months ago

I am also getting this crash on

LLVM (http://llvm.org/):
  LLVM version 18.1.8
  Optimized build.

also tried updating to newest MSVC

[2/2] Processing file C:\Users\sla-t\source\repos\CMEP\EngineLogging\src\Logging.cpp.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: clang-tidy EngineLogging\\src\\ConsoleColors.cpp EngineLogging\\src\\Logging.cpp
1.      <eof> parser at end of file
2.      While analyzing stack: 
        #0 Calling std::thread::id::id(_Thrd_id_t) at line C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\include\thread:260:12
        #1 Calling std::this_thread::get_id() at line 81
        #2 Calling Logging::(anonymous namespace)::GetCurrentThreadID() at line 135
        #3 Calling Logging::Logger::StartLog(Logging::LogLevel) at line 197
        #4 Calling Logging::Logger::SimpleLog(LogLevel, const char *)
3.      C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\include\thread:238:50: Error evaluating initializer
Exception Code: 0xC0000005
 #0 0x00007ff681b26b19 (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x20e6b19)
 #1 0x00007ff681898393 (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x1e58393)
 #2 0x00007ff6818982b5 (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x1e582b5)
 #3 0x00007ff68189b95d (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x1e5b95d)
 #4 0x00007ff680eb7320 (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x1477320)
 #5 0x00007ff680ec77a7 (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x14877a7)
 #6 0x00007ff680ec43b1 (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x14843b1)
 #7 0x00007ff680ec3805 (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x1483805)
 #8 0x00007ff680ed70c0 (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x14970c0)
 #9 0x00007ff680ed634c (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x149634c)
#10 0x00007ff680ca1b61 (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x1261b61)
#11 0x00007ff680c960ba (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x12560ba)
#12 0x00007ff680ca9263 (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x1269263)
#13 0x00007ff68074b208 (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0xd0b208)
#14 0x00007ff67fa5d981 (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x1d981)
#15 0x00007ff67fa5d3f2 (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x1d3f2)
#16 0x00007ff67ff41ae7 (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x501ae7)
#17 0x00007ff67fdbe245 (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x37e245)
#18 0x00007ff67ff41985 (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x501985)
#19 0x00007ff67ff407cb (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x5007cb)
#20 0x00007ff67ff4307c (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x50307c)
#21 0x00007ff67fdba0a9 (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x37a0a9)
#22 0x00007ff67fd84b01 (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x344b01)
#23 0x00007ff680bd94b0 (D:\Appz\LLVM_Clang_18_1_8\bin\clang-tidy.exe+0x11994b0)
#24 0x00007ff9f9d1257d (C:\WINDOWS\System32\KERNEL32.DLL+0x1257d)
#25 0x00007ff9fa98aa48 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x5aa48)

Relevant file

Clang compiles it without issue. Doesn't crash when -clang-analyzer-* is specified, unsure if that helps