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

clangd crashes on trivial constexpr declaration (windows) #1672

Closed
helmesjo opened this issue Jun 12, 2023 · 21 comments
Closed

clangd crashes on trivial constexpr declaration (windows) #1672

helmesjo opened this issue Jun 12, 2023 · 21 comments
Assignees

Comments

@helmesjo
Copy link

clangd crashes on the camera_option_default_value variable. Interestingly enough, it does not crash if the constant is renamed to (for example) default_value. Just from playing around it appears to be somewhat related to the length of the line (or name?).

// header1.hxx
#pragma once

constexpr const char* const camera_option_default_value = "-";
// header2.hxx
#pragma once

#include <header1.hxx>

Logs

[11:50:02.821] Building preamble...
Exception Code: 0xC0000005
 #0 0x00007ff696d19efc (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0x1e49efc)
 #1 0x00007ff696d19c6b (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0x1e49c6b)
 #2 0x00007ff696d19c0b (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0x1e49c0b)
 #3 0x00007ff696d19c6b (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0x1e49c6b)
 #4 0x00007ff696d19c6b (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0x1e49c6b)
 #5 0x00007ff696d0e928 (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0x1e3e928)
 #6 0x00007ff696d0fe05 (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0x1e3fe05)
 #7 0x00007ff696d163b1 (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0x1e463b1)
 #8 0x00007ff696cf00eb (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0x1e200eb)
 #9 0x00007ff696cee01e (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0x1e1e01e)
#10 0x00007ff696cd432e (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0x1e0432e)
#11 0x00007ff696b947fe (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0x1cc47fe)
#12 0x00007ff696c18fa7 (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0x1d48fa7)
#13 0x00007ff696b6aed7 (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0x1c9aed7)
#14 0x00007ff696b6a9cb (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0x1c9a9cb)
#15 0x00007ff696b92d42 (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0x1cc2d42)
#16 0x00007ff695d7d4f3 (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0xead4f3)
#17 0x00007ff694f803e9 (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0xb03e9)
#18 0x00007ff694f82177 (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0xb2177)
#19 0x00007ff694f774ba (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0xa74ba)
#20 0x00007ff696a95af0 (C:\Users\fho\AppData\Local\Microsoft\WinGet\Links\clangd.exe+0x1bc5af0)
#21 0x00007ff9f48d26ad (C:\WINDOWS\System32\KERNEL32.DLL+0x126ad)
#22 0x00007ff9f63ea9f8 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x5a9f8)
Segmentation fault

System information

Output of clangd --version:

clangd version 16.0.2

Editor/LSP plugin:

Operating system:
Windows 11

@HighCommander4
Copy link

Does the crash happen as soon as you open the file containing the variable? Or do you have to perform any particular editor action to trigger the crash?

@helmesjo
Copy link
Author

Yeah sorry, that would be clangd --check=header2.hxx.

@HighCommander4
Copy link

Can you also show the contents of any relevant config files that are present (compile_commands.json, .clangd, .clang-tidy, compile_flags.txt)?

(With the default configuration, the include in header2.hxx cannot be resolved because the compiler does not search the current directory when the #include <...> syntax is used.)

@helmesjo
Copy link
Author

helmesjo commented Jun 14, 2023

I distilled it down to this same setup, though in a project I'm working on. I've tried to set it up the same (copying my .clangd & compile_commands.json, then modifying for these headers above), but can't get the same error. I'm guessing there is a memory buildup or something happning earlier in the process, and it happens to be triggered by this exact line (constexpr const char* const camera_option_default_value = "-"), so a reproducer might be hard.

Is there any way I can debug this locally and share some logs, dump etc. (without building all of llvm that is)?

@HighCommander4
Copy link

A few ideas:

  • Can you try disabling clang-tidy checks by adding --clang-tidy=false to clangd's command line? Sometimes a crash is in a checker and can be worked around by disabling the checker.
  • Can you try the latest weekly snapshot release at https://github.com/clangd/clangd/releases? Maybe the issue has been fixed on trunk.

For further diagnosis it would be helpful to get a symbolicated backtrace (so it shows where in the code the crash is). I'm not sure how to do that on Windows, maybe someone else who is more familiar with Windows can chime in.

@helmesjo
Copy link
Author

helmesjo commented Jul 3, 2023

@HighCommander4

  1. Adding --clang-tidy=false didn't help, still crashes.
  2. Tried the snapshot, still crashes.

I'll look into building from source, though isn't it possible to build clangd as a standalone? I only found this. Building the full monstrosity LLVM just to try this out seems excessive. I mean just cloning the repository is a big pain and I recon building will take possibly and hour or more.

Anyways, thanks for the suggstions!

@helmesjo
Copy link
Author

helmesjo commented Jul 3, 2023

Alright, it sure took a while but here is the symbolized callstack:

Note that this is 16.0.2

Assertion failed: isa<T>(*this) && "Invalid accessor called", file C:\git\thirdparty\llvm-project\llvm\include\llvm/ADT/PointerUnion.h, line 156
Exception Code: 0x80000003
 #0 0x00007ff6695e761c HandleAbort C:\git\thirdparty\llvm-project\llvm\lib\Support\Windows\Signals.inc:419:0
 #1 0x00007ffe60558e05 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xa8e05)
 #2 0x00007ffe6055ab29 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xaab29)
 #3 0x00007ffe60561025 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xb1025)
 #4 0x00007ffe605608b7 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xb08b7)
 #5 0x00007ffe6055e881 (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xae881)
 #6 0x00007ffe6056158f (C:\WINDOWS\SYSTEM32\ucrtbased.dll+0xb158f)
 #7 0x00007ff6717473b1 llvm::PointerUnion<class clang::ValueDecl const *, class clang::Expr const *, class clang::TypeInfoLValue, class clang::DynamicAllocLValue>::get<class clang::ValueDecl const *>(void) const C:\git\thirdparty\llvm-project\llvm\include\llvm\ADT\PointerUnion.h:156:0
 #8 0x00007ff6717473f7 clang::APValue::LValueBase::get<class clang::ValueDecl const *>(void) const C:\git\thirdparty\llvm-project\clang\include\clang\AST\APValue.h:164:0
 #9 0x00007ff671fe567d clang::serialization::BasicWriterBase<class clang::ASTRecordWriter>::writeAPValue(class clang::APValue const &) C:\git\thirdparty\llvm-project\build\tools\clang\include\clang\AST\AbstractBasicWriter.inc:920:0
#10 0x00007ff671fe0a1e clang::serialization::WriteDispatcher<class clang::APValue>::write<class clang::ASTRecordWriter, class clang::APValue const &>(class clang::ASTRecordWriter &, class clang::APValue const &) C:\git\thirdparty\llvm-project\build\tools\clang\include\clang\AST\AbstractBasicWriter.inc:30:0
#11 0x00007ff671fe0b9f clang::serialization::DataStreamBasicWriter<class clang::ASTRecordWriter>::writeArray<class clang::APValue>(class llvm::ArrayRef<class clang::APValue>) C:\git\thirdparty\llvm-project\clang\include\clang\AST\AbstractBasicWriter.h:146:0
#12 0x00007ff671fe52a5 clang::serialization::BasicWriterBase<class clang::ASTRecordWriter>::writeAPValue(class clang::APValue const &) C:\git\thirdparty\llvm-project\build\tools\clang\include\clang\AST\AbstractBasicWriter.inc:871:0
#13 0x00007ff671fe0a1e clang::serialization::WriteDispatcher<class clang::APValue>::write<class clang::ASTRecordWriter, class clang::APValue const &>(class clang::ASTRecordWriter &, class clang::APValue const &) C:\git\thirdparty\llvm-project\build\tools\clang\include\clang\AST\AbstractBasicWriter.inc:30:0
#14 0x00007ff671fe0b9f clang::serialization::DataStreamBasicWriter<class clang::ASTRecordWriter>::writeArray<class clang::APValue>(class llvm::ArrayRef<class clang::APValue>) C:\git\thirdparty\llvm-project\clang\include\clang\AST\AbstractBasicWriter.h:146:0
#15 0x00007ff671fe5228 clang::serialization::BasicWriterBase<class clang::ASTRecordWriter>::writeAPValue(class clang::APValue const &) C:\git\thirdparty\llvm-project\build\tools\clang\include\clang\AST\AbstractBasicWriter.inc:869:0
#16 0x00007ff671fe0a1e clang::serialization::WriteDispatcher<class clang::APValue>::write<class clang::ASTRecordWriter, class clang::APValue const &>(class clang::ASTRecordWriter &, class clang::APValue const &) C:\git\thirdparty\llvm-project\build\tools\clang\include\clang\AST\AbstractBasicWriter.inc:30:0
#17 0x00007ff671fe0b9f clang::serialization::DataStreamBasicWriter<class clang::ASTRecordWriter>::writeArray<class clang::APValue>(class llvm::ArrayRef<class clang::APValue>) C:\git\thirdparty\llvm-project\clang\include\clang\AST\AbstractBasicWriter.h:146:0
#18 0x00007ff671fe52a5 clang::serialization::BasicWriterBase<class clang::ASTRecordWriter>::writeAPValue(class clang::APValue const &) C:\git\thirdparty\llvm-project\build\tools\clang\include\clang\AST\AbstractBasicWriter.inc:871:0
#19 0x00007ff671fe0a1e clang::serialization::WriteDispatcher<class clang::APValue>::write<class clang::ASTRecordWriter, class clang::APValue const &>(class clang::ASTRecordWriter &, class clang::APValue const &) C:\git\thirdparty\llvm-project\build\tools\clang\include\clang\AST\AbstractBasicWriter.inc:30:0
#20 0x00007ff671fe0b9f clang::serialization::DataStreamBasicWriter<class clang::ASTRecordWriter>::writeArray<class clang::APValue>(class llvm::ArrayRef<class clang::APValue>) C:\git\thirdparty\llvm-project\clang\include\clang\AST\AbstractBasicWriter.h:146:0
#21 0x00007ff671fe52a5 clang::serialization::BasicWriterBase<class clang::ASTRecordWriter>::writeAPValue(class clang::APValue const &) C:\git\thirdparty\llvm-project\build\tools\clang\include\clang\AST\AbstractBasicWriter.inc:871:0
#22 0x00007ff671fe1f8e clang::ASTRecordWriter::AddAPValue(class clang::APValue const &) C:\git\thirdparty\llvm-project\clang\include\clang\Serialization\ASTRecordWriter.h:175:0
#23 0x00007ff671fd3866 clang::ASTDeclWriter::VisitLifetimeExtendedTemporaryDecl(class clang::LifetimeExtendedTemporaryDecl *) C:\git\thirdparty\llvm-project\clang\lib\Serialization\ASTWriterDecl.cpp:1200:0
#24 0x00007ff671fe273f clang::declvisitor::Base<struct std::add_pointer, class clang::ASTDeclWriter, void>::Visit(class clang::Decl *) C:\git\thirdparty\llvm-project\build\tools\clang\include\clang\AST\DeclNodes.inc:95:0
#25 0x00007ff671fcb7f8 clang::ASTDeclWriter::Visit(class clang::Decl *) C:\git\thirdparty\llvm-project\clang\lib\Serialization\ASTWriterDecl.cpp:281:0
#26 0x00007ff671fcaf0f clang::ASTWriter::WriteDecl(class clang::ASTContext &, class clang::Decl *) C:\git\thirdparty\llvm-project\clang\lib\Serialization\ASTWriterDecl.cpp:2471:0
#27 0x00007ff671f289dd clang::ASTWriter::WriteASTCore(class clang::Sema &, class llvm::StringRef, class clang::Module *) C:\git\thirdparty\llvm-project\clang\lib\Serialization\ASTWriter.cpp:4997:0
#28 0x00007ff671f2a70f clang::ASTWriter::WriteAST(class clang::Sema &, class llvm::StringRef, class clang::Module *, class llvm::StringRef, bool, bool) C:\git\thirdparty\llvm-project\clang\lib\Serialization\ASTWriter.cpp:4547:0
#29 0x00007ff671f0da90 clang::PCHGenerator::HandleTranslationUnit(class clang::ASTContext &) C:\git\thirdparty\llvm-project\clang\lib\Serialization\GeneratePCH.cpp:68:0
#30 0x00007ff6718eb7ae `anonymous namespace'::PrecompilePreambleConsumer::HandleTranslationUnit C:\git\thirdparty\llvm-project\clang\lib\Frontend\PrecompiledPreamble.cpp:297:0
#31 0x00007ff671d700e1 clang::ParseAST(class clang::Sema &, bool, bool) C:\git\thirdparty\llvm-project\clang\lib\Parse\ParseAST.cpp:203:0
#32 0x00007ff671893dba clang::ASTFrontendAction::ExecuteAction(void) C:\git\thirdparty\llvm-project\clang\lib\Frontend\FrontendAction.cpp:1167:0
#33 0x00007ff6718936ce clang::FrontendAction::Execute(void) C:\git\thirdparty\llvm-project\clang\lib\Frontend\FrontendAction.cpp:1062:0
#34 0x00007ff6718e706a clang::PrecompiledPreamble::Build(class clang::CompilerInvocation const &, class llvm::MemoryBuffer const *, struct clang::PreambleBounds, class clang::DiagnosticsEngine &, class llvm::IntrusiveRefCntPtr<class llvm::vfs::FileSystem>, class std::shared_ptr<class clang::PCHContainerOperations>, bool, class clang::PreambleCallbacks &) C:\git\thirdparty\llvm-project\clang\lib\Frontend\PrecompiledPreamble.cpp:522:0
#35 0x00007ff66c9d26bd clang::clangd::buildPreamble(class llvm::StringRef, class clang::CompilerInvocation, struct clang::clangd::ParseInputs const &, bool, class std::function<(class clang::ASTContext &, class clang::Preprocessor &, class clang::clangd::CanonicalIncludes const &)>, struct clang::clangd::PreambleBuildStats *) C:\git\thirdparty\llvm-project\clang-tools-extra\clangd\Preamble.cpp:545:0
#36 0x00007ff6690beeb8 clang::clangd::`anonymous namespace'::Checker::buildAST C:\git\thirdparty\llvm-project\clang-tools-extra\clangd\tool\Check.cpp:209:0
#37 0x00007ff6690c18d3 clang::clangd::check(class llvm::StringRef, class clang::clangd::ThreadsafeFS const &, struct clang::clangd::ClangdLSPServer::Options const &) C:\git\thirdparty\llvm-project\clang-tools-extra\clangd\tool\Check.cpp:462:0
#38 0x00007ff6690637a8 main C:\git\thirdparty\llvm-project\clang-tools-extra\clangd\tool\ClangdMain.cpp:993:0
#39 0x00007ff6714d1c69 invoke_main D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:79:0
#40 0x00007ff6714d1b4e __scrt_common_main_seh D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288:0
#41 0x00007ff6714d1a0e __scrt_common_main D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:331:0
#42 0x00007ff6714d1cfe mainCRTStartup D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:17:0
#43 0x00007ffedcea26ad (C:\WINDOWS\System32\KERNEL32.DLL+0x126ad)
#44 0x00007ffede28a9f8 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x5a9f8)

Edit
I guess it's somewhere around here it starts to go haywire (the call that hits the assert):
llvm-project\build\tools\clang\include\clang\AST\AbstractBasicWriter.inc
image

@helmesjo
Copy link
Author

helmesjo commented Jul 3, 2023

Further digging:

If I change line 920 above to just call lvalueBase.getType() instead of doing the casting first, then it ends up evaluating is<DynamicAllocLValue>() to true here:

image

and things move along for a bit, but then in some other part of the codebase it'll do the same const ValueDecl* cast and crash in the same way as before.

@HighCommander4
Copy link

isn't it possible to build clangd as a standalone?

Just to address this point: no, clangd cannot currently be built standalone, though I've suggested this in #1375.

However, even if that were possible, it would not have been very helpful in this case, since the crash is not directly in clangd code, but in clang code invoked by clangd code (in the stack trace you posted, everything above frame 34 is clang code). With a hypothetical standalone build, those frames would be in a prebuilt clang library and so presumably wouldn't be symbolized.

That said, it shouldn't be necessary to do a local build to get a symbolized stack trace; having llvm-symbolizer in the PATH should be sufficient (though I've heard users report this not working on Windows; I'm not sure why).


Anyways, it's great for debugging purposes that you have a local build! I'll have a look at your findings and see if I can suggest something to try.

@HighCommander4
Copy link

It looks like, when DynamicAllocLValue was added as a fourth possible type of the variant in LValueBase::Ptr, adding serialization support for this option was overlooked.

@HighCommander4 HighCommander4 self-assigned this Jul 5, 2023
@HighCommander4
Copy link

@helmesjo could you try applying the patch at https://reviews.llvm.org/D154471 locally, and see if it fixes the crash for you?

@helmesjo
Copy link
Author

helmesjo commented Jul 5, 2023

isn't it possible to build clangd as a standalone?

Just to address this point: no, clangd cannot currently be built standalone, though I've suggested this in #1375.

However, even if that were possible, it would not have been very helpful in this case, since the crash is not directly in clangd code, but in clang code invoked by clangd code (in the stack trace you posted, everything above frame 34 is clang code). With a hypothetical standalone build, those frames would be in a prebuilt clang library and so presumably wouldn't be symbolized.

That said, it shouldn't be necessary to do a local build to get a symbolized stack trace; having llvm-symbolizer in the PATH should be sufficient (though I've heard users report this not working on Windows; I'm not sure why).


Anyways, it's great for debugging purposes that you have a local build! I'll have a look at your findings and see if I can suggest something to try.

Thanks for the detailed reply!

@helmesjo
Copy link
Author

helmesjo commented Jul 5, 2023

@helmesjo could you try applying the patch at https://reviews.llvm.org/D154471 locally, and see if it fixes the crash for you?

Sure, will do!

@helmesjo
Copy link
Author

helmesjo commented Jul 5, 2023

@HighCommander4
I applied the patch to 16.0.2 but still a crash... Still "Invalid accessor called" but a different callstack.
I'll try it on master as well.

@HighCommander4
Copy link

I applied the patch to 16.0.2 but still a crash... Still "Invalid accessor called" but a different callstack.

Could you post the stack please? It should allow us to determine whether it's the same issue cropping up somewhere else, or a different issue.

@helmesjo
Copy link
Author

helmesjo commented Jul 6, 2023

I applied the patch to 16.0.2 but still a crash... Still "Invalid accessor called" but a different callstack.

Could you post the stack please? It should allow us to determine whether it's the same issue cropping up somewhere else, or a different issue.

16.0.2 + patch D154471

        clangd.exe!HandleAbort(int Sig) Line 419	C++
 	[External Code]	
 	clangd.exe!llvm::PointerUnion<clang::ValueDecl const *,clang::Expr const *,clang::TypeInfoLValue,clang::DynamicAllocLValue>::get<clang::ValueDecl const *>() Line 156	C++
 	clangd.exe!clang::APValue::LValueBase::get<clang::ValueDecl const *>() Line 164	C++
 	clangd.exe!clang::serialization::BasicWriterBase<clang::ASTRecordWriter>::writeAPValue(const clang::APValue & node) Line 972	C++
 	clangd.exe!clang::serialization::WriteDispatcher<clang::APValue>::write<clang::ASTRecordWriter,clang::APValue const &>(clang::ASTRecordWriter & W, const clang::APValue & <args_0>) Line 30	C++
 	clangd.exe!clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeArray<clang::APValue>(llvm::ArrayRef<clang::APValue> array) Line 146	C++
 	clangd.exe!clang::serialization::BasicWriterBase<clang::ASTRecordWriter>::writeAPValue(const clang::APValue & node) Line 871	C++
 	clangd.exe!clang::serialization::WriteDispatcher<clang::APValue>::write<clang::ASTRecordWriter,clang::APValue const &>(clang::ASTRecordWriter & W, const clang::APValue & <args_0>) Line 30	C++
 	clangd.exe!clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeArray<clang::APValue>(llvm::ArrayRef<clang::APValue> array) Line 146	C++
 	clangd.exe!clang::serialization::BasicWriterBase<clang::ASTRecordWriter>::writeAPValue(const clang::APValue & node) Line 869	C++
 	clangd.exe!clang::serialization::WriteDispatcher<clang::APValue>::write<clang::ASTRecordWriter,clang::APValue const &>(clang::ASTRecordWriter & W, const clang::APValue & <args_0>) Line 30	C++
 	clangd.exe!clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeArray<clang::APValue>(llvm::ArrayRef<clang::APValue> array) Line 146	C++
 	clangd.exe!clang::serialization::BasicWriterBase<clang::ASTRecordWriter>::writeAPValue(const clang::APValue & node) Line 871	C++
 	clangd.exe!clang::serialization::WriteDispatcher<clang::APValue>::write<clang::ASTRecordWriter,clang::APValue const &>(clang::ASTRecordWriter & W, const clang::APValue & <args_0>) Line 30	C++
 	clangd.exe!clang::serialization::DataStreamBasicWriter<clang::ASTRecordWriter>::writeArray<clang::APValue>(llvm::ArrayRef<clang::APValue> array) Line 146	C++
 	clangd.exe!clang::serialization::BasicWriterBase<clang::ASTRecordWriter>::writeAPValue(const clang::APValue & node) Line 871	C++
 	clangd.exe!clang::ASTRecordWriter::AddAPValue(const clang::APValue & Value) Line 175	C++
 	clangd.exe!clang::ASTDeclWriter::VisitLifetimeExtendedTemporaryDecl(clang::LifetimeExtendedTemporaryDecl * D) Line 1200	C++
 	clangd.exe!clang::declvisitor::Base<std::add_pointer,clang::ASTDeclWriter,void>::Visit(clang::Decl * D) Line 95	C++
 	clangd.exe!clang::ASTDeclWriter::Visit(clang::Decl * D) Line 281	C++
 	clangd.exe!clang::ASTWriter::WriteDecl(clang::ASTContext & Context, clang::Decl * D) Line 2471	C++
 	clangd.exe!clang::ASTWriter::WriteASTCore(clang::Sema & SemaRef, llvm::StringRef isysroot, clang::Module * WritingModule) Line 4997	C++
 	clangd.exe!clang::ASTWriter::WriteAST(clang::Sema & SemaRef, llvm::StringRef OutputFile, clang::Module * WritingModule, llvm::StringRef isysroot, bool hasErrors, bool ShouldCacheASTInMemory) Line 4547	C++
 	clangd.exe!clang::PCHGenerator::HandleTranslationUnit(clang::ASTContext & Ctx) Line 68	C++
 	clangd.exe!`anonymous namespace'::PrecompilePreambleConsumer::HandleTranslationUnit(clang::ASTContext & Ctx) Line 297	C++
 	clangd.exe!clang::ParseAST(clang::Sema & S, bool PrintStats, bool SkipFunctionBodies) Line 203	C++
 	clangd.exe!clang::ASTFrontendAction::ExecuteAction() Line 1167	C++
 	clangd.exe!clang::FrontendAction::Execute() Line 1062	C++
 	clangd.exe!clang::PrecompiledPreamble::Build(const clang::CompilerInvocation & Invocation, const llvm::MemoryBuffer * MainFileBuffer, clang::PreambleBounds Bounds, clang::DiagnosticsEngine & Diagnostics, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> VFS, std::shared_ptr<clang::PCHContainerOperations> PCHContainerOps, bool StoreInMemory, clang::PreambleCallbacks & Callbacks) Line 522	C++
 	clangd.exe!clang::clangd::buildPreamble(llvm::StringRef FileName, clang::CompilerInvocation CI, const clang::clangd::ParseInputs & Inputs, bool StoreInMemory, std::function<void __cdecl(clang::ASTContext &,clang::Preprocessor &,clang::clangd::CanonicalIncludes const &)> PreambleCallback, clang::clangd::PreambleBuildStats * Stats) Line 545	C++
 	clangd.exe!clang::clangd::`anonymous namespace'::Checker::buildAST() Line 209	C++
 	clangd.exe!clang::clangd::check(llvm::StringRef File, const clang::clangd::ThreadsafeFS & TFS, const clang::clangd::ClangdLSPServer::Options & Opts) Line 462	C++
 	clangd.exe!main(int argc, char * * argv) Line 993	C++
 	[External Code]	

@HighCommander4
Copy link

Thanks. The stack trace suggests underlying issue is the same, i.e. my patch is incomplete. I'll take another crack at it.

@HighCommander4
Copy link

Ok, I believe I found the issue and updated the patch at https://reviews.llvm.org/D154471 to fix it.

@helmesjo could you give it another try with the updated version of the patch?

@helmesjo
Copy link
Author

helmesjo commented Jul 7, 2023

@HighCommander4
I gave it a try (main + D154471) and it indeed solves the crash in my case! I'll try 16.0.2 as well just for kicks.

Edit
16.0.2 + D154471 works fine as well.

@HighCommander4
Copy link

Thanks for checking! I submitted the patch for review.

@HighCommander4
Copy link

This was fixed in clangd 17.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants