| Issue |
202334
|
| Summary |
clangd/clang-tidy crash while parsing std::expected<void, std::error_code> code with libstdc++ <expected>
|
| Labels |
|
| Assignees |
|
| Reporter |
delafthi
|
### Summary
clangd/clang-tidy crashes intermittently while parsing C++23 code using `std::expected<void, std::error_code>` (and in one trace while instantiating `std::expected<unsigned char, std::error_code>` from libstdc++ `<expected>`).
I can reproduce in multiple translation units in same project (`file.cpp`, `operations.cpp`).
### Environment
- clangd: 21.1.8
- LLVM: 21.1.8
- GCC/libstdc++: 15.2.0
- Platform: x86_64 Linux (Nix)
### Observed behavior
Clang frontend crashes during parse/instantiation.
One crash report:
```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. /home/deaa/Projects/zhaw/fitonduty/soldier_device/lib/zephyr-cpp/fs/src/file.cpp:36:1: current parser token '{'
1. /home/deaa/Projects/zhaw/fitonduty/soldier_device/lib/zephyr-cpp/fs/src/file.cpp:12:1: parsing namespace 'fs'
2. /home/deaa/Projects/zhaw/fitonduty/soldier_device/lib/zephyr-cpp/fs/src/file.cpp:15:1: parsing namespace 'fs::(anonymous)'
3. /nix/store/jdh5b9bbhykq1cgfph5q3mf7a4503izs-gcc-15.2.0/include/c++/15.2.0/expected:335:11: instantiating class definition 'std::expected<unsigned char, std::error_code>'
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0 libLLVM.so.21.1 0x00007b7ebe940448 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1 libLLVM.so.21.1 0x00007b7ebe93d1e7
2 libc.so.6 0x00007b7ebd442790
3 libclang-cpp.so.21.1 0x00007b7eca1a6118 clang::TemplateDeclInstantiator::VisitVarTemplatePartialSpecializationDecl(clang::VarTemplatePartialSpecializationDecl*) + 56
4 libclang-cpp.so.21.1 0x00007b7eca11850c clang::Sema::InstantiateClass(clang::SourceLocation, clang::CXXRecordDecl*, clang::CXXRecordDecl*, clang::MultiLevelTemplateArgumentList const&, clang::TemplateSpecializationKind, bool) + 3452
5 libclang-cpp.so.21.1 0x00007b7eca147543 clang::Sema::InstantiateClassTemplateSpecialization(clang::SourceLocation, clang::ClassTemplateSpecializationDecl*, clang::TemplateSpecializationKind, bool, bool) + 355
6 libclang-cpp.so.21.1 0x00007b7eca1bb776
7 libclang-cpp.so.21.1 0x00007b7ec8849a70 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) + 80
8 libclang-cpp.so.21.1 0x00007b7eca1d8f68 clang::Sema::RequireCompleteTypeImpl(clang::SourceLocation, clang::QualType, clang::Sema::CompleteTypeKind, clang::Sema::TypeDiagnoser*) + 2088
9 libclang-cpp.so.21.1 0x00007b7eca1d91c8 clang::Sema::RequireCompleteType(clang::SourceLocation, clang::QualType, clang::Sema::CompleteTypeKind, clang::Sema::TypeDiagnoser&) + 24
10 libclang-cpp.so.21.1 0x00007b7eca1d97f1 clang::Sema::RequireCompleteType(clang::SourceLocation, clang::QualType, clang::Sema::CompleteTypeKind, unsigned int) + 49
11 libclang-cpp.so.21.1 0x00007b7ec99a40f7 clang::Sema::ActOnStartOfFunctionDef(clang::Scope*, clang::Decl*, clang::SkipBodyInfo*, clang::Sema::FnBodyKind) + 3639
12 libclang-cpp.so.21.1 0x00007b7ec99c02b4 clang::Sema::ActOnStartOfFunctionDef(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>, clang::SkipBodyInfo*, clang::Sema::FnBodyKind) + 148
13 libclang-cpp.so.21.1 0x00007b7ec8ba77cc clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) + 956
14 libclang-cpp.so.21.1 0x00007b7ec8a933bd clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) + 5405
15 libclang-cpp.so.21.1 0x00007b7ec8ba15f9 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) + 953
16 libclang-cpp.so.21.1 0x00007b7ec8ba2463 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) + 899
17 libclang-cpp.so.21.1 0x00007b7ec8bac1a6 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) + 598
18 libclang-cpp.so.21.1 0x00007b7ec8ab37c6 clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) + 534
19 libclang-cpp.so.21.1 0x00007b7ec8ab696f clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) + 3167
20 libclang-cpp.so.21.1 0x00007b7ec8a954fc clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) + 940
21 libclang-cpp.so.21.1 0x00007b7ec8bac410 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) + 1216
22 libclang-cpp.so.21.1 0x00007b7ec8ab37c6 clang::Parser::ParseInnerNamespace(llvm::SmallVector<clang::Parser::InnerNamespaceInfo, 4u> const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) + 534
23 libclang-cpp.so.21.1 0x00007b7ec8ab696f clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) + 3167
24 libclang-cpp.so.21.1 0x00007b7ec8a954fc clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) + 940
25 libclang-cpp.so.21.1 0x00007b7ec8bac410 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) + 1216
26 libclang-cpp.so.21.1 0x00007b7ec8bad425 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) + 581
27 libclang-cpp.so.21.1 0x00007b7ec8bad902 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) + 66
28 libclang-cpp.so.21.1 0x00007b7ec8a5bd07 clang::ParseAST(clang::Sema&, bool, bool) + 535
29 libclang-cpp.so.21.1 0x00007b7ecb02cc88 clang::FrontendAction::Execute() + 40
30 clangd-unwrapped 0x00005679fc2fc533
31 clangd-unwrapped 0x00005679fc388569
32 clangd-unwrapped 0x00005679fc388f2a
33 clangd-unwrapped 0x00005679fc38ad67
34 clangd-unwrapped 0x00005679fc38b0e1
35 clangd-unwrapped 0x00005679fc5e4332
36 libc.so.6 0x00007b7ebd49dd53
37 libc.so.6 0x00007b7ebd5255fc
```
Another recent crash:
```
Stack dump:
0. /home/deaa/Projects/zhaw/fitonduty/soldier_device/lib/zephyr-cpp/fs/src/operations.cpp:16:1: current parser token '{'
1. /home/deaa/Projects/zhaw/fitonduty/soldier_device/lib/zephyr-cpp/fs/src/operations.cpp:12:1: parsing namespace 'fs'
```
### Notes
- Upgrading clang to v22 did not fix crash on my side.
- Crash seems triggered by normal function definitions returning `std::expected<void, std::error_code>` in this TU, and one trace points into `std::expected<unsigned char, std::error_code>` instantiation from libstdc++.
If needed, I can provide a reduced repro TU extracted from this project.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs