Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang-format] Assertion failed in FormatToken.cpp #117290

Open
rmarker opened this issue Nov 22, 2024 · 0 comments
Open

[clang-format] Assertion failed in FormatToken.cpp #117290

rmarker opened this issue Nov 22, 2024 · 0 comments
Labels
clang-format crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@rmarker
Copy link
Contributor

rmarker commented Nov 22, 2024

I encountered a crash with clang-format 19.1.4 (well, initially with 19.1.0 before I tried the newer version).

I built a debug version and got the following output.
(Including the debug output as it seemed to have more information than the regular version that I initially encountered. E.g. it mentioned the assertion)

Assertion failed: i < MustBreakBeforeItem.size(), file \clang\lib\Format\FormatToken.cpp, line 271
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: clang-format.exe ./temp.C
Exception Code: 0x80000003
0x00007FF67CF7EF7C, clang-format.exe(0x00007FF67CDD0000) + 0x1AEF7C byte(s), HandleAbort() + 0xC byte(s), \llvm\lib\Support\Windows\Signals.inc, line 429 + 0x0 byte(s)
0x00007FF8E7B090ED, C:\WINDOWS\SYSTEM32\ucrtbased.dll(0x00007FF8E7A60000) + 0xA90ED byte(s), raise() + 0x46D byte(s)
0x00007FF8E7B0AE49, C:\WINDOWS\SYSTEM32\ucrtbased.dll(0x00007FF8E7A60000) + 0xAAE49 byte(s), abort() + 0x39 byte(s)
0x00007FF8E7B11345, C:\WINDOWS\SYSTEM32\ucrtbased.dll(0x00007FF8E7A60000) + 0xB1345 byte(s), _get_wide_winmain_command_line() + 0x2895 byte(s)
0x00007FF8E7B10BD7, C:\WINDOWS\SYSTEM32\ucrtbased.dll(0x00007FF8E7A60000) + 0xB0BD7 byte(s), _get_wide_winmain_command_line() + 0x2127 byte(s)
0x00007FF8E7B0EBA1, C:\WINDOWS\SYSTEM32\ucrtbased.dll(0x00007FF8E7A60000) + 0xAEBA1 byte(s), _get_wide_winmain_command_line() + 0xF1 byte(s)
0x00007FF8E7B118AF, C:\WINDOWS\SYSTEM32\ucrtbased.dll(0x00007FF8E7A60000) + 0xB18AF byte(s), _wassert() + 0x2F byte(s)
0x00007FF67D11B13E, clang-format.exe(0x00007FF67CDD0000) + 0x34B13E byte(s), clang::format::CommaSeparatedList::precomputeFormattingInfos() + 0x75E byte(s), \clang\lib\Format\FormatToken.cpp, line 271 + 0x40 byte(s)
0x00007FF67D120B18, clang-format.exe(0x00007FF67CDD0000) + 0x350B18 byte(s), clang::format::TokenAnnotator::calculateFormattingInformation() + 0xF08 byte(s), \clang\lib\Format\TokenAnnotator.cpp, line 4071 + 0x44 byte(s)
0x00007FF67D11FCA5, clang-format.exe(0x00007FF67CDD0000) + 0x34FCA5 byte(s), clang::format::TokenAnnotator::calculateFormattingInformation() + 0x95 byte(s), \clang\lib\Format\TokenAnnotator.cpp, line 3866 + 0x12 byte(s)
0x00007FF67D0B5D8E, clang-format.exe(0x00007FF67CDD0000) + 0x2E5D8E byte(s), clang::format::`anonymous namespace'::SemiRemover::removeSemi() + 0x10E byte(s), \clang\lib\Format\Format.cpp, line 2305 + 0x0 byte(s)
0x00007FF67D0B5C31, clang-format.exe(0x00007FF67CDD0000) + 0x2E5C31 byte(s), clang::format::`anonymous namespace'::SemiRemover::analyze() + 0x71 byte(s), \clang\lib\Format\Format.cpp, line 2282 + 0x19 byte(s)
0x00007FF67D1553D1, clang-format.exe(0x00007FF67CDD0000) + 0x3853D1 byte(s), clang::format::TokenAnalyzer::process() + 0x621 byte(s), \clang\lib\Format\TokenAnalyzer.cpp, line 129 + 0x4B byte(s)
0x00007FF67D0C142C, clang-format.exe(0x00007FF67CDD0000) + 0x2F142C byte(s), `clang::format::internal::reformat'::`36'::<lambda_5>::operator()() + 0x6C byte(s), \clang\lib\Format\Format.cpp, line 3716 + 0x3D byte(s)
0x00007FF67D0E5D18, clang-format.exe(0x00007FF67CDD0000) + 0x315D18 byte(s), std::invoke<`clang::format::internal::reformat'::`36'::<lambda_5> &,clang::format::Environment const &>() + 0x28 byte(s), C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.42.34433\include\type_traits, line 1705 + 0x14 byte(s)
0x00007FF67D0C35CF, clang-format.exe(0x00007FF67CDD0000) + 0x2F35CF byte(s), std::_Func_impl_no_alloc<`clang::format::internal::reformat'::`36'::<lambda_5>,std::pair<clang::tooling::Replacements,unsigned int>,clang::format::Environment const &>::_Do_call() + 0x2F byte(s), C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.42.34433\include\functional, line 876 + 0x1B byte(s)
0x00007FF67D10883E, clang-format.exe(0x00007FF67CDD0000) + 0x33883E byte(s), std::_Func_class<std::pair<clang::tooling::Replacements,unsigned int>,clang::format::Environment const &>::operator()() + 0x5E byte(s), C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.42.34433\include\functional, line 920 + 0x24 byte(s)
0x00007FF67D0C070D, clang-format.exe(0x00007FF67CDD0000) + 0x2F070D byte(s), clang::format::internal::reformat() + 0xD2D byte(s), \clang\lib\Format\Format.cpp, line 3768 + 0x4F byte(s)
0x00007FF67D0B1DC9, clang-format.exe(0x00007FF67CDD0000) + 0x2E1DC9 byte(s), clang::format::reformat() + 0xB9 byte(s), \clang\lib\Format\Format.cpp, line 3812 + 0x9C byte(s)
0x00007FF67CE22679, clang-format.exe(0x00007FF67CDD0000) + 0x52679 byte(s), clang::format::format() + 0x1789 byte(s), \clang\tools\clang-format\ClangFormat.cpp, line 510 + 0x1F2 byte(s)
0x00007FF67CE249DA, clang-format.exe(0x00007FF67CDD0000) + 0x549DA byte(s), main() + 0x81A byte(s), \clang\tools\clang-format\ClangFormat.cpp, line 734 + 0x88 byte(s)
0x00007FF67D4876C9, clang-format.exe(0x00007FF67CDD0000) + 0x6B76C9 byte(s), invoke_main() + 0x39 byte(s), D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl, line 79 + 0x0 byte(s)
0x00007FF67D4875B2, clang-format.exe(0x00007FF67CDD0000) + 0x6B75B2 byte(s), __scrt_common_main_seh() + 0x132 byte(s), D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl, line 288 + 0x5 byte(s)
0x00007FF67D48746E, clang-format.exe(0x00007FF67CDD0000) + 0x6B746E byte(s), __scrt_common_main() + 0xE byte(s), D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl, line 331 + 0x0 byte(s)
0x00007FF67D48775E, clang-format.exe(0x00007FF67CDD0000) + 0x6B775E byte(s), mainCRTStartup() + 0xE byte(s), D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp, line 17 + 0x0 byte(s)
0x00007FFA0C95259D, C:\WINDOWS\System32\KERNEL32.DLL(0x00007FFA0C940000) + 0x1259D byte(s), BaseThreadInitThunk() + 0x1D byte(s)
0x00007FFA0DC4AF38, C:\WINDOWS\SYSTEM32\ntdll.dll(0x00007FFA0DBF0000) + 0x5AF38 byte(s), RtlUserThreadStart() + 0x28 byte(s)

I managed to reduce the offending code to the following reproducible case:

void foo::bar()
{
  auto sgf = [&](const dimC& U)
  {
      std::array<Tfloat64, 39> ogl = {
        dimC::Mi() * 0.001,
        dimC::Mi() * 0.01,
        dimC::Mi() * 0.1,
        dimC::Mi() * 0.5,
        dimC::Mi(),
        dimC::Mi() * 5,
        dimC::Mi() * 10,
        dimC::Mi() * 50,
        dimC::Mi() * 100,
        dimC::Mi() * 500,
        dimC::T(),
        dimC::T() * 5,
        dimC::T() * 10,
        dimC::T() * 50,
        dimC::T() * 100,
        dimC::T() * 500,
        dimC::I(),
        dimC::I() * 6,
        dimC::F(),
        dimC::Y(),
        dimC::Y() * 4,
        dimC::Y() * 8,
        dimC::Y() * 8 * 4,
        dimC::Y() * 8 * 4 * 5,
        dimC::Y() * 8 * 8 * 5,
        dimC::Mi() / 2,
        dimC::Mi(),
        dimC::Mi() * 5,
        dimC::Mi() * 10,
        dimC::Mi() * 50,
        dimC::Mi() * 100,
        dimC::Mi() * 500,
        dimC::Mi() * 1000,
        dimC::Mi() * 5000,
        dimC::Mi() * 10000,
        dimC::Mi() * 50000,
        dimC::Mi() * 100000,
        dimC::Mi() * 500000,
        dimC::Mi() * 1000000,
      };
  };
}

I then tried it with the current main, but it also hit the assertion.

@EugeneZelenko EugeneZelenko added the crash Prefer [crash-on-valid] or [crash-on-invalid] label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-format crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

2 participants