[clangd][clang] Crash in SignatureHelp on invalid decltype(__uuidof(...)) assertion in PPCaching.cpp:151
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
The crash is reproducibly triggered by `textDocument/signatureHelp` on the declaration line of the minimized repro,near the end of the parameter declarator.
Assertion:
```
CachedTokens[CachedLexPos-1].getLastLoc() == Tok.getAnnotationEndLoc() && "The annotation should be until the most recent cached token
```
```
initialize -> initialized -> didOpen -> textDocument/signatureHelp-> shutdown -> exit
```
source code
```cxx
template void test_uuidofExpr(decltype(__uuidof(T::member)) arg) {}
```
It crashes no matter whether `-fms-extensions` is enabled.
Maybe it's related to https://github.com/llvm/llvm-project/issues/165246, since its shares similar crash point and assertion, but the stacktrace is no the same.
```
clangd: /tmp/llvm-project-main-20260504/clang/lib/Lex/PPCaching.cpp:151: void clang::Preprocessor::AnnotatePreviousCachedTokens(const clang::Token&): Assertion `CachedTokens[CachedLexPos-1].getLastLoc() == Tok.getAnnotationEndLoc() && "The annotation should be until the most recent cached token"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0. /tmp/uuidof-final-oCwIYc/microsoft-uuidof-mangling.cpp:1:41: at annotation token
I[00:16:47.712] Indexing c++20 standard library in the context of /tmp/uuidof-final-oCwIYc/microsoft-uuidof-mangling.cpp
I[00:16:47.713] --> textDocument/publishDiagnostics
I[00:16:47.722] <-- exit
I[00:16:47.722] LSP finished, exiting with status 1
I[00:16:48.644] Indexed c++20 standard library (incomplete due to errors): 15508 symbols, 2887 filtered
#0 0x00006296f41238f2 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /tmp/llvm-project-main-20260504/llvm/lib/Support/Unix/Signals.inc:884:3
#1 0x00006296f412066c llvm::sys::RunSignalHandlers() /tmp/llvm-project-main-20260504/llvm/lib/Support/Signals.cpp:108:20
#2 0x00006296f4120ee1 SignalHandler(int, siginfo_t*, void*) /tmp/llvm-project-main-20260504/llvm/lib/Support/Unix/Signals.inc:448:14
#3 0x00007bfe4ea45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x00007bfe4ea9eb2c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
#5 0x00007bfe4ea9eb2c __pthread_kill_internal ./nptl/pthread_kill.c:78:10
#6 0x00007bfe4ea9eb2c pthread_kill ./nptl/pthread_kill.c:89:10
#7 0x00007bfe4ea4527e raise ./signal/../sysdeps/posix/raise.c:27:6
#8 0x00007bfe4ea288ff abort ./stdlib/abort.c:81:7
#9 0x00007bfe4ea2881b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007bfe4ea3b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
#11 0x00006296f4a13bbe clang::Preprocessor::AnnotatePreviousCachedTokens(clang::Token const&) /tmp/llvm-project-main-20260504/clang/lib/Lex/PPCaching.cpp:150:3
#12 0x00006296f6028fb0 clang::NestedNameSpecifierLocBuilder::~NestedNameSpecifierLocBuilder() /tmp/llvm-project-main-20260504/clang/include/clang/AST/NestedNameSpecifierBase.h:462:5
#13 0x00006296f6028fb0 clang::CXXScopeSpec::~CXXScopeSpec() /tmp/llvm-project-main-20260504/clang/include/clang/Sema/DeclSpec.h:75:9
#14 0x00006296f6028fb0 clang::DeclSpec::~DeclSpec() /tmp/llvm-project-main-20260504/clang/include/clang/Sema/DeclSpec.h:219:7
#15 0x00006296f6028fb0 clang::Parser::ParseOptionalCXXScopeSpecifier(clang::CXXScopeSpec&, clang::OpaquePtr, bool, bool, bool*, bool, clang::IdentifierInfo const**, bool, bool, bool, bool, bool) /tmp/llvm-project-main-20260504/clang/lib/Parse/ParseExprCXX.cpp:185:3
#16 0x00006296f5fa20f9 clang::Parser::TryAnnotateTypeOrScopeToken(clang::ImplicitTypenameContext, bool) /tmp/llvm-project-main-20260504/clang/lib/Parse/Parser.cpp:1977:5
#17 0x00006296f60aad13 clang::Parser::isCXXDeclarationSpecifier(clang::ImplicitTypenameContext, clang::Parser::TPResult, bool*) /tmp/llvm-project-main-20260504/clang/lib/Parse/ParseTentative.cpp:1166:5
#18 0x00006296f60adde2 clang::Parser::TryParseParameterDeclarationClause(bool*, bool, clang::ImplicitTypenameContext) /tmp/llvm-project-main-20260504/clang/lib/Parse/ParseTentative.cpp:1772:5
#19 0x00006296f60ae3e6 clang::Parser::isCXXFunctionDeclarator(bool*, clang::ImplicitTypenameContext) /tmp/llvm-project-main-20260504/clang/lib/Parse/ParseTentative.cpp:1706:3
#20 0x00006296f5fec890 llvm::SmallVectorBase::size() const /tmp/llvm-project-main-20260504/llvm/include/llvm/ADT/SmallVector.h:83:32
#21 0x00006296f5fec890 llvm::SmallVectorTemplateBase::pop_back() /tmp/llvm-project-main-20260504/llvm/include/llvm/ADT/SmallVector.h:573:46
#22 0x00006296f5fec890 clang::Parser::ParseDirectDeclarator(clang::Declarator&) /tmp/llvm-project-main-20260504/clang/lib/Parse/ParseDecl.cpp:6973:48
#23 0x00006296f5fe5915 clang::Parser::ParseDeclaratorInternal(clang::Declarator&, void (clang::Parser::*)(clang::Declarator&)) /tmp/llvm-project-main-20260504/clang/lib/Parse/ParseDecl.cpp:6642:1
#24 0x00006296f6464903 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref) /tmp/llvm-project-main-20260504/clang/lib/Basic/StackExhaustionHandler.cpp:21:1
#25 0x00006296f5fe14d1 clang::Declarator::hasName() const /tmp/llvm-project-main-20260504/clang/include/clang/Sema/DeclSpec.h:2363:63
#26 0x00006296f5fe14d1 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) /tmp/llvm-project-main-20260504/clang/lib/Parse/ParseDecl.cpp:2179:17
#27 0x00006296f609d116 clang::Parser::ParseDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) /tmp/llvm-project-main-20260504/clang/lib/Parse/ParseTemplate.cpp:228:71
#28 0x00006296f60a8106 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (.part.0) /tmp/llvm-project-main-20260504/clang/lib/Parse/ParseTemplate.cpp:147:39
#29 0x00006296f60a8535 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) /tmp/llvm-project-main-20260504/clang/lib/Parse/ParseTemplate.cpp:38:32
#30 0x00006296f60a8535 clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&) /tmp/llvm-project-main-20260504/clang/lib/Parse/ParseTemplate.cpp:43:50
#31 0x00006296f5fe5583 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) /tmp/llvm-project-main-20260504/clang/lib/Parse/ParseDecl.cpp:1915:48
#32 0x00006296f5faa95d clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) /tmp/llvm-project-main-20260504/clang/lib/Parse/Parser.cpp:937:30
#33 0x00006296f5fac237 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) /tmp/llvm-project-main-20260504/clang/lib/Parse/Parser.cpp:711:36
#34 0x00006296f5fac6d3 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) /tmp/llvm-project-main-20260504/clang/lib/Parse/Parser.cpp:608:32
#35 0x00006296f5f90aaa clang::ParseAST(clang::Sema&, bool, bool) /tmp/llvm-project-main-20260504/clang/lib/Parse/ParseAST.cpp:169:69
#36 0x00006296f5d8a6e7 clang::FrontendAction::Execute() /tmp/llvm-project-main-20260504/clang/lib/Frontend/FrontendAction.cpp:1346:38
#37 0x00006296f55e983c llvm::Error::getPtr() const /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/Error.h:278:51
#38 0x00006296f55e983c llvm::Error::operator bool() /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/Error.h:241:22
#39 0x00006296f55e983c clang::clangd::(anonymous namespace)::semaCodeComplete(std::unique_ptr>, clang::CodeCompleteOptions const&, clang::clangd::(anonymous namespace)::SemaCompleteInput const&, clang::clangd::IncludeStructure*) (.isra.0) /tmp/llvm-project-main-20260504/clang-tools-extra/clangd/CodeComplete.cpp:1464:41
#40 0x00006296f55eadbc std::unique_ptr>::~unique_ptr() /usr/include/c++/13/bits/unique_ptr.h:403:12
#41 0x00006296f55eadbc clang::clangd::signatureHelp(llvm::StringRef, clang::clangd::Position, clang::clangd::PreambleData const&, clang::clangd::ParseInputs const&, clang::clangd::MarkupKind) /tmp/llvm-project-main-20260504/clang-tools-extra/clangd/CodeComplete.cpp:2353:19
#42 0x00006296f55c897c std::_Vector_base>::_Vector_impl_data::_Vector_impl_data(std::_Vector_base>::_Vector_impl_data&&) /usr/include/c++/13/bits/stl_vector.h:107:4
#43 0x00006296f55c897c std::_Vector_base>::_Vector_impl::_Vector_impl(std::_Vector_base>::_Vector_impl&&) /usr/include/c++/13/bits/stl_vector.h:155:68
#44 0x00006296f55c897c std::_Vector_base>::_Vector_base(std::_Vector_base>&&) /usr/include/c++/13/bits/stl_vector.h:338:7
#45 0x00006296f55c897c std::vector>::vector(std::vector>&&) /usr/include/c++/13/bits/stl_vector.h:620:7
#46 0x00006296f55c897c clang::clangd::SignatureHelp::SignatureHelp(clang::clangd::SignatureHelp&&) /tmp/llvm-project-main-20260504/clang-tools-extra/clangd/Protocol.h:1456:8
#47 0x00006296f55c897c llvm::Expected::Expected(clang::clangd::SignatureHelp&&, std::enable_if, void>::type*) /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/Error.h:535:5
#48 0x00006296f55c897c clang::clangd::ClangdServer::signatureHelp(llvm::StringRef, clang::clangd::Position, clang::clangd::MarkupKind, llvm::unique_function)>)::'lambda'(llvm::Expected)::operator()(llvm::Expected) /tmp/llvm-project-main-20260504/clang-tools-extra/clangd/ClangdServer.cpp:519:7
#49 0x00006296f55c8f03 llvm::Expected::assertIsChecked() const /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/Error.h:729:9
#50 0x00006296f55c8f03 llvm::Expected::~Expected() /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/Error.h:566:20
#51 0x00006296f55c8f03 void llvm::detail::UniqueFunctionBase>::CallImpl)>)::'lambda'(llvm::Expected)>(void*, llvm::Expected&) /tmp/llvm-project-main-20260504/llvm/include/llvm/ADT/FunctionExtras.h:212:16
#52 0x00006296f580f2eb llvm::Expected::assertIsChecked() const /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/Error.h:729:9
#53 0x00006296f580f2eb llvm::Expected::~Expected() /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/Error.h:566:20
#54 0x00006296f580f2eb clang::clangd::TUScheduler::runWithPreamble(llvm::StringRef, llvm::StringRef, clang::clangd::TUScheduler::PreambleConsistency, llvm::unique_function)>)::'lambda'()::operator()() /tmp/llvm-project-main-20260504/clang-tools-extra/clangd/TUScheduler.cpp:1810:11
#55 0x00006296f59edb6e llvm::detail::UniqueFunctionBase::operator=(llvm::detail::UniqueFunctionBase&&) /tmp/llvm-project-main-20260504/llvm/include/llvm/ADT/FunctionExtras.h:329:5
#56 0x00006296f59edb6e llvm::detail::UniqueFunctionBase::operator=(llvm::detail::UniqueFunctionBase&&) /tmp/llvm-project-main-20260504/llvm/include/llvm/ADT/FunctionExtras.h:321:23
#57 0x00006296f59edb6e llvm::unique_function::operator=(llvm::unique_function&&) /tmp/llvm-project-main-20260504/llvm/include/llvm/ADT/FunctionExtras.h:352:20
#58 0x00006296f59edb6e operator() /tmp/llvm-project-main-20260504/clang-tools-extra/clangd/support/Threading.cpp:103:14
#59 0x00006296f59edb6e operator())::&> /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/thread.h:46:16
#60 0x00006296f59edb6e __invoke_impl):: > >(void*)::, clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function)::&> /usr/include/c++/13/bits/invoke.h:61:36
#61 0x00006296f59edb6e __invoke):: > >(void*)::, clang::clangd::AsyncTaskRunner::runAsync(const llvm::Twine&, llvm::unique_function)::&> /usr/include/c++/13/bits/invoke.h:96:40
#62 0x00006296f59edb6e __apply_impl):: > >(void*)::, std::tuple):: >&, 0> /usr/include/c++/13/tuple:2302:27
#63 0x00006296f59edb6e apply):: > >(void*)::, std::tuple):: >&> /usr/include/c++/13/tuple:2313:31
#64 0x00006296f59edb6e GenericThreadProxy):: > > /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/thread.h:44:15
#65 0x00006296f59edb6e void* llvm::thread::ThreadProxy)::'lambda0'()>>(void*) /tmp/llvm-project-main-20260504/llvm/include/llvm/Support/thread.h:62:36
#66 0x00007bfe4ea9caa4 start_thread ./nptl/pthread_create.c:447:8
#67 0x00007bfe4eb29c6c clone3 ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:80:0
Signalled during preamble action: SignatureHelp
Filename: microsoft-uuidof-mangling.cpp
Directory: /tmp/uuidof-final-oCwIYc
Command Line: /usr/lib/llvm-18/bin/clang -resource-dir=/tmp/build-assert-clangd-main-20260506/lib/clang/23 -- /tmp/uuidof-final-oCwIYc/microsoft-uuidof-mangling.cpp
```
Contributor guide
Assessment
This issue has not been assessed yet.