llvm / llvm-project

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

clang-tidy Crash on 'std::format' with Latest MSVC #93271

Open c0nstexpr opened 6 months ago

c0nstexpr commented 6 months ago

Platform: Windows MSVC version: 14.40 Clang Tidy version: 18.1

Code:

#include <format>

using namespace std;

auto foo()
{
    return format("Hello, {}!", "world");
}

Log:

> [build] [2/3  66% :: 14.460] Building CXX object CMakeFiles\cppcmake.dir\src\main.cpp.obj
> [build] FAILED: CMakeFiles/cppcmake.dir/src/main.cpp.obj 
> [build] cmake.exe -E __run_co_compile --tidy="D:/Program Files/LLVM/bin/clang-tidy.exe;--enable-check-profile;--store-check-profile=D:/Documents/cppcmake/build/Visual Studio Community 2022 Release - amd64-Debug/clang-tidy-report;--extra-arg=/EHsc;--extra-arg=/std:c++latest;--extra-arg=-Wno-unknown-warning-option;--extra-arg-before=--driver-mode=cl" --source=D:\Documents\cppcmake\src\main.cpp -- "D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\Hostx64\x64\cl.exe"  /nologo /TP  -ID:\Documents\cppcmake\include -external:I"D:\Documents\cppcmake\build\Visual Studio Community 2022 Release - amd64-Debug\vcpkg_installed\x64-windows\include" -external:W0 /DWIN32 /D_WINDOWS /EHsc /Zi /Ob0 /Od /RTC1 -std:c++20 -MDd /utf-8 /diagnostics:caret /W4 -WX /showIncludes /FoCMakeFiles\cppcmake.dir\src\main.cpp.obj /FdCMakeFiles\cppcmake.dir\ /FS -c D:\Documents\cppcmake\src\main.cpp
> [build] Error running 'D:/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.
> [build] Stack dump:
> [build] 1.    <eof> parser at end of file
> [build] 2.    While analyzing stack: 
> [build]   #0 Calling std::_Fmt_write(class std::back_insert_iterator<class std::_Fmt_buffer<char> >, const basic_string_view<char>) at line D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:3518:16
> [build]   #1 Calling std::_Default_arg_formatter<std::back_insert_iterator<std::_Fmt_buffer<char>>, char>::operator()(class std::basic_string_view<char>) at line D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:781:20 <Spelling=D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\yvals_core.h:1951:17>
> [build]   #2 Calling std::basic_format_arg<std::basic_format_context<std::back_insert_iterator<std::_Fmt_buffer<char>>, char>>::_Visit(struct std::_Default_arg_formatter<class std::back_insert_iterator<class std::_Fmt_buffer<char> >, char> &&) at line D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:916:12
> [build]   #3 Calling std::visit_format_arg(struct std::_Default_arg_formatter<class std::back_insert_iterator<class std::_Fmt_buffer<char> >, char> &&, basic_format_arg<basic_format_context<back_insert_iterator<_Fmt_buffer<char> >, char> >) at line D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:3621:25 <Spelling=D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\yvals_core.h:1951:17>
> [build]   #4 Calling std::_Format_handler<char>::_On_replacement_field(const size_t, const char *) at line D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:1465:9
> [build]   #5 Calling std::_Parse_replacement_field(const char *, const char *, struct std::_Format_handler<char> &) at line D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:1531:18
> [build]   #6 Calling std::_Parse_format_string(basic_string_view<char>, struct std::_Format_handler<char> &) at line D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:3742:9
> [build]   #7 Calling std::vformat_to(class std::back_insert_iterator<class std::basic_string<char> >, const string_view, const format_args) at line D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:3819:5 <Spelling=D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\yvals_core.h:1951:17>
> [build]   #8 Calling std::vformat(const string_view, const format_args) at line D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:3849:12 <Spelling=D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\yvals_core.h:1951:17>
> [build]   #9 Calling std::format(const format_string<const char (&)[6]>, const char (&)[6]) at line 8
> [build]   #10 Calling foo()
> [build] 3.    D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:2586:33 <Spelling=D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\yvals_core.h:1951:17>: Error evaluating statement
> [build] 4.    D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:2586:33 <Spelling=D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\yvals_core.h:1951:17>: Error evaluating statement
> [build] Exception Code: 0xC0000005
> [build]  #0 0x00007ff6dfc40a1e (D:\Program Files\LLVM\bin\clang-tidy.exe+0x17d0a1e)
> [build]  #1 0x00007ff6e02120eb (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1da20eb)
> [build]  #2 0x00007ff6df8e7170 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1477170)
> [build]  #3 0x00007ff6df8f75f7 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x14875f7)
> [build]  #4 0x00007ff6dfc94ca1 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1824ca1)
> [build]  #5 0x00007ff6dfc97551 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1827551)
> [build]  #6 0x00007ff6df8f5c9b (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1485c9b)
> [build]  #7 0x00007ff6df8f37d1 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x14837d1)
> [build]  #8 0x00007ff6df8f361b (D:\Program Files\LLVM\bin\clang-tidy.exe+0x148361b)
> [build]  #9 0x00007ff6df906f10 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1496f10)
> [build] #10 0x00007ff6df90619c (D:\Program Files\LLVM\bin\clang-tidy.exe+0x149619c)
> [build] #11 0x00007ff6df6d1ac1 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1261ac1)
> [build] #12 0x00007ff6df6c601a (D:\Program Files\LLVM\bin\clang-tidy.exe+0x125601a)
> [build] #13 0x00007ff6df6d91c3 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x12691c3)
> [build] #14 0x00007ff6df177448 (D:\Program Files\LLVM\bin\clang-tidy.exe+0xd07448)
> [build] #15 0x00007ff6de48d981 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1d981)
> [build] #16 0x00007ff6de48d3f2 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1d3f2)
> [build] #17 0x00007ff6de96db77 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x4fdb77)
> [build] #18 0x00007ff6de7ea2c5 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x37a2c5)
> [build] #19 0x00007ff6de96da15 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x4fda15)
> [build] #20 0x00007ff6de96c85b (D:\Program Files\LLVM\bin\clang-tidy.exe+0x4fc85b)
> [build] #21 0x00007ff6de96f10c (D:\Program Files\LLVM\bin\clang-tidy.exe+0x4ff10c)
> [build] #22 0x00007ff6de7e6129 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x376129)
> [build] #23 0x00007ff6de7b0b21 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x340b21)
> [build] #24 0x00007ff6df608f60 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1198f60)
> [build] #25 0x00007ffdf6b17344 (C:\Windows\System32\KERNEL32.DLL+0x17344)
> [build] #26 0x00007ffdf88026b1 (C:\Windows\SYSTEM32\ntdll.dll+0x526b1)
> [build] Access violation
> [build] ninja: build stopped: subcommand failed.
llvmbot commented 6 months ago

@llvm/issue-subscribers-clang-tidy

Author: c0nstexpr (c0nstexpr)

Platform: Windows MSVC version: 14.40 Clang Tidy version: 18.1 Code: ``` #include <format> using namespace std; auto foo() { return format("Hello, {}!", "world"); } ``` Log: > [build] [2/3 66% :: 14.460] Building CXX object CMakeFiles\cppcmake.dir\src\main.cpp.obj > [build] FAILED: CMakeFiles/cppcmake.dir/src/main.cpp.obj > [build] cmake.exe -E __run_co_compile --tidy="D:/Program Files/LLVM/bin/clang-tidy.exe;--enable-check-profile;--store-check-profile=D:/Documents/cppcmake/build/Visual Studio Community 2022 Release - amd64-Debug/clang-tidy-report;--extra-arg=/EHsc;--extra-arg=/std:c++latest;--extra-arg=-Wno-unknown-warning-option;--extra-arg-before=--driver-mode=cl" --source=D:\Documents\cppcmake\src\main.cpp -- "D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\Hostx64\x64\cl.exe" /nologo /TP -ID:\Documents\cppcmake\include -external:I"D:\Documents\cppcmake\build\Visual Studio Community 2022 Release - amd64-Debug\vcpkg_installed\x64-windows\include" -external:W0 /DWIN32 /D_WINDOWS /EHsc /Zi /Ob0 /Od /RTC1 -std:c++20 -MDd /utf-8 /diagnostics:caret /W4 -WX /showIncludes /FoCMakeFiles\cppcmake.dir\src\main.cpp.obj /FdCMakeFiles\cppcmake.dir\ /FS -c D:\Documents\cppcmake\src\main.cpp > [build] Error running 'D:/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. > [build] Stack dump: > [build] 1. <eof> parser at end of file > [build] 2. While analyzing stack: > [build] #0 Calling std::_Fmt_write(class std::back_insert_iterator<class std::_Fmt_buffer<char> >, const basic_string_view<char>) at line D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:3518:16 > [build] #1 Calling std::_Default_arg_formatter<std::back_insert_iterator<std::_Fmt_buffer<char>>, char>::operator()(class std::basic_string_view<char>) at line D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:781:20 <Spelling=D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\yvals_core.h:1951:17> > [build] #2 Calling std::basic_format_arg<std::basic_format_context<std::back_insert_iterator<std::_Fmt_buffer<char>>, char>>::_Visit(struct std::_Default_arg_formatter<class std::back_insert_iterator<class std::_Fmt_buffer<char> >, char> &&) at line D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:916:12 > [build] #3 Calling std::visit_format_arg(struct std::_Default_arg_formatter<class std::back_insert_iterator<class std::_Fmt_buffer<char> >, char> &&, basic_format_arg<basic_format_context<back_insert_iterator<_Fmt_buffer<char> >, char> >) at line D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:3621:25 <Spelling=D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\yvals_core.h:1951:17> > [build] #4 Calling std::_Format_handler<char>::_On_replacement_field(const size_t, const char *) at line D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:1465:9 > [build] #5 Calling std::_Parse_replacement_field(const char *, const char *, struct std::_Format_handler<char> &) at line D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:1531:18 > [build] #6 Calling std::_Parse_format_string(basic_string_view<char>, struct std::_Format_handler<char> &) at line D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:3742:9 > [build] #7 Calling std::vformat_to(class std::back_insert_iterator<class std::basic_string<char> >, const string_view, const format_args) at line D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:3819:5 <Spelling=D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\yvals_core.h:1951:17> > [build] #8 Calling std::vformat(const string_view, const format_args) at line D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:3849:12 <Spelling=D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\yvals_core.h:1951:17> > [build] #9 Calling std::format(const format_string<const char (&)[6]>, const char (&)[6]) at line 8 > [build] #10 Calling foo() > [build] 3. D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:2586:33 <Spelling=D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\yvals_core.h:1951:17>: Error evaluating statement > [build] 4. D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\format:2586:33 <Spelling=D:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\include\yvals_core.h:1951:17>: Error evaluating statement > [build] Exception Code: 0xC0000005 > [build] #0 0x00007ff6dfc40a1e (D:\Program Files\LLVM\bin\clang-tidy.exe+0x17d0a1e) > [build] #1 0x00007ff6e02120eb (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1da20eb) > [build] #2 0x00007ff6df8e7170 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1477170) > [build] #3 0x00007ff6df8f75f7 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x14875f7) > [build] #4 0x00007ff6dfc94ca1 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1824ca1) > [build] #5 0x00007ff6dfc97551 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1827551) > [build] #6 0x00007ff6df8f5c9b (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1485c9b) > [build] #7 0x00007ff6df8f37d1 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x14837d1) > [build] #8 0x00007ff6df8f361b (D:\Program Files\LLVM\bin\clang-tidy.exe+0x148361b) > [build] #9 0x00007ff6df906f10 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1496f10) > [build] #10 0x00007ff6df90619c (D:\Program Files\LLVM\bin\clang-tidy.exe+0x149619c) > [build] #11 0x00007ff6df6d1ac1 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1261ac1) > [build] #12 0x00007ff6df6c601a (D:\Program Files\LLVM\bin\clang-tidy.exe+0x125601a) > [build] #13 0x00007ff6df6d91c3 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x12691c3) > [build] #14 0x00007ff6df177448 (D:\Program Files\LLVM\bin\clang-tidy.exe+0xd07448) > [build] #15 0x00007ff6de48d981 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1d981) > [build] #16 0x00007ff6de48d3f2 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1d3f2) > [build] #17 0x00007ff6de96db77 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x4fdb77) > [build] #18 0x00007ff6de7ea2c5 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x37a2c5) > [build] #19 0x00007ff6de96da15 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x4fda15) > [build] #20 0x00007ff6de96c85b (D:\Program Files\LLVM\bin\clang-tidy.exe+0x4fc85b) > [build] #21 0x00007ff6de96f10c (D:\Program Files\LLVM\bin\clang-tidy.exe+0x4ff10c) > [build] #22 0x00007ff6de7e6129 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x376129) > [build] #23 0x00007ff6de7b0b21 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x340b21) > [build] #24 0x00007ff6df608f60 (D:\Program Files\LLVM\bin\clang-tidy.exe+0x1198f60) > [build] #25 0x00007ffdf6b17344 (C:\Windows\System32\KERNEL32.DLL+0x17344) > [build] #26 0x00007ffdf88026b1 (C:\Windows\SYSTEM32\ntdll.dll+0x526b1) > [build] Access violation > [build] ninja: build stopped: subcommand failed.
pdeiml commented 4 months ago

Are there any news about this problem?

PiotrZSL commented 4 months ago

Not checked, but there is a chance that it is fixed by 0e62d5cf55479981da5e05e406bbca4afb3cdc4f

willenbr24 commented 4 days ago

I got the same problem with msvc 14.42.34433 and clang 18.1.8. A workaround for me was to disable clang-analyzer-* for the affected source code.