llvm / llvm/llvm-project

Clang crashes while diagnosing invalid in-class member initializer

Open
#178,440 4 comments 0 reactions 0 assignees View on GitHub
clang:frontend crash needs-reduction
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Clang crashes during diagnostic formatting when compiling invalid code (in-class member initializer with function pointer to non-existing symbol / wrong namespace).
Instead of emitting a diagnostic, clang crashes in Diagnostic::FormatDiagnostic.

Version:
clang version 21.1.8
Target: x86_64-w64-windows-gnu
Thread model: posix

Command:
clang++ -fsyntax-only context.hpp

Stackstrace

```sh
wusik@LAPTOP-4PA9J0V4:app3d clang++ -fsyntax-only modules/acul/include/acul/detail/simd/context.hpp
modules/acul/include/acul/detail/simd/context.hpp:13:9: error: unknown type name 'PFN_fill_line_buffer'; did you mean
'fs::detail::PFN_fill_line_buffer'?
13 | PFN_fill_line_buffer fill_line_buffer = &nosimd::fill_line_buffer;
| ^~~~~~~~~~~~~~~~~~~~
| fs::detail::PFN_fill_line_buffer
modules/acul/include/acul/detail/simd/../../io/fs/detail/file_simd_fn.hpp:23:11: note: 'fs::detail::PFN_fill_line_buffer' declared here
23 | using PFN_fill_line_buffer = void (*)(const char *data, size_t size, string_view_pool &dst);
| ^
modules/acul/include/acul/detail/simd/context.hpp:13:50: error: no member named 'fill_line_buffer' in namespace 'acul::detail::nosimd';
did you mean simply 'fill_line_buffer'?
13 | PFN_fill_line_buffer fill_line_buffer = &nosimd::fill_line_buffer;
| ^~~~~~~~~~~~~~~~~~~~~~~~
| fill_line_buffer
modules/acul/include/acul/detail/simd/context.hpp:13:30: note: 'fill_line_buffer' declared here
13 | PFN_fill_line_buffer fill_line_buffer = &nosimd::fill_line_buffer;
| ^
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0. Program arguments: C:\\msys64\\clang64\\bin\\clang++.exe -fsyntax-only modules/acul/include/acul/detail/simd/context.hpp
1. parser at end of file
2. modules/acul/include/acul/detail/simd/context.hpp:7:1: parsing namespace 'acul'
3. modules/acul/include/acul/detail/simd/context.hpp:9:23: parsing struct/union/class body 'acul::detail::simd_context'
Exception Code: 0xC0000005
#0 0x00007ffc8e930581 clang::TemplateSpecializationType const* clang::Type::getAs() const (C:\msys64\clang64\bin\libclang-cpp.dll+0x1f0581)
#1 0x00007ffc8f2c4d7f clang::FormatUTFCodeUnitAsCodepoint(unsigned int, clang::QualType) (C:\msys64\clang64\bin\libclang-cpp.dll+0xb84d7f)
#2 0x00007ffc8f08d0d4 clang::FormatASTNodeDiagnosticArgument(clang::DiagnosticsEngine::ArgumentKind, long long, llvm::StringRef, llvm::StringRef, llvm::ArrayRef>, llvm::SmallVectorImpl&, void*, llvm::ArrayRef) (C:\msys64\clang64\bin\libclang-cpp.dll+0x94d0d4)
#3 0x00007ffc8f0a8296 clang::Diagnostic::FormatDiagnostic(char const*, char const*, llvm::SmallVectorImpl&) const (C:\msys64\clang64\bin\libclang-cpp.dll+0x968296)
#4 0x00007ffc8f0a72f4 clang::Diagnostic::FormatDiagnostic(llvm::SmallVectorImpl&) const (C:\msys64\clang64\bin\libclang-cpp.dll+0x9672f4)
#5 0x00007ffc8f0a6c73 clang::TextDiagnosticPrinter::HandleDiagnostic(clang::DiagnosticsEngine::Level, clang::Diagnostic const&) (C:\msys64\clang64\bin\libclang-cpp.dll+0x966c73)
#6 0x00007ffc8e86cee1 clang::DiagnosticsEngine::EmitDiagnostic(clang::DiagnosticBuilder const&, bool) (C:\msys64\clang64\bin\libclang-cpp.dll+0x12cee1)
#7 0x00007ffc8e9ddbb5 clang::Sema::EmitDiagnostic(unsigned int, clang::DiagnosticBuilder const&) (C:\msys64\clang64\bin\libclang-cpp.dll+0x29dbb5)
#8 0x00007ffc8e9d97cc clang::SemaBase::ImmediateDiagBuilder::~ImmediateDiagBuilder() (C:\msys64\clang64\bin\libclang-cpp.dll+0x2997cc)
#9 0x00007ffc8e9d76fc clang::SemaBase::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() (C:\msys64\clang64\bin\libclang-cpp.dll+0x2976fc)
#10 0x00007ffc8f090862 clang::InitializationSequence::Diagnose(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::ArrayRef) (C:\msys64\clang64\bin\libclang-cpp.dll+0x950862)
#11 0x00007ffc8ecc809e clang::InitializationSequence::Perform(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef, clang::QualType*) (C:\msys64\clang64\bin\libclang-cpp.dll+0x58809e)
#12 0x00007ffc8ed1168c clang::Sema::ConvertMemberDefaultInitExpression(clang::FieldDecl*, clang::Expr*, clang::SourceLocation) (C:\msys64\clang64\bin\libclang-cpp.dll+0x5d168c)
#13 0x00007ffc8ed1148d clang::Sema::ActOnFinishCXXInClassMemberInitializer(clang::Decl*, clang::SourceLocation, clang::ActionResult) (C:\msys64\clang64\bin\libclang-cpp.dll+0x5d148d)
#14 0x00007ffc8ed10fa5 clang::Parser::ParseLexedMemberInitializer(clang::Parser::LateParsedMemberInitializer&) (C:\msys64\clang64\bin\libclang-cpp.dll+0x5d0fa5)
#15 0x00007ffc8e7ccdea clang::Parser::ParseLexedMemberInitializers(clang::Parser::ParsingClass&) (C:\msys64\clang64\bin\libclang-cpp.dll+0x8cdea)
#16 0x00007ffc8e7c95d8 clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributes&, unsigned int, clang::Decl*) (C:\msys64\clang64\bin\libclang-cpp.dll+0x895d8)
#17 0x00007ffc8ed956be clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributes&) (C:\msys64\clang64\bin\libclang-cpp.dll+0x6556be)
#18 0x00007ffc8e88e503 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::Parser::LateParsedAttrList*, clang::ImplicitTypenameContext) (C:\msys64\clang64\bin\libclang-cpp.dll+0x14e503)
#19 0x00007ffc8ed1fa6e clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (C:\msys64\clang64\bin\libclang-cpp.dll+0x5dfa6e)
#20 0x00007ffc8ed1db45 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (C:\msys64\clang64\bin\libclang-cpp.dll+0x5ddb45)
#21 0x00007ffc8ed1d641 clang::Parser::ParseInnerNamespace(llvm::SmallVector const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) (C:\msys64\clang64\bin\libclang-cpp.dll+0x5dd641)
#22 0x00007ffc8ed1d761 clang::Parser::ParseInnerNamespace(llvm::SmallVector const&, unsigned int, clang::SourceLocation&, clang::ParsedAttributes&, clang::BalancedDelimiterTracker&) (C:\msys64\clang64\bin\libclang-cpp.dll+0x5dd761)
#23 0x00007ffc8ed1c085 clang::Parser::ParseNamespace(clang::DeclaratorContext, clang::SourceLocation&, clang::SourceLocation) (C:\msys64\clang64\bin\libclang-cpp.dll+0x5dc085)
#24 0x00007ffc8ed1eb8a clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (C:\msys64\clang64\bin\libclang-cpp.dll+0x5deb8a)
#25 0x00007ffc8ed1da34 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (C:\msys64\clang64\bin\libclang-cpp.dll+0x5dda34)
#26 0x00007ffc8ef58451 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&, clang::Sema::ModuleImportState&) (C:\msys64\clang64\bin\libclang-cpp.dll+0x818451)
#27 0x00007ffc8ef58114 clang::ParseAST(clang::Sema&, bool, bool) (C:\msys64\clang64\bin\libclang-cpp.dll+0x818114)
#28 0x00007ffc8ef80e2f clang::FrontendAction::Execute() (C:\msys64\clang64\bin\libclang-cpp.dll+0x840e2f)
#29 0x00007ffc8ef8099b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (C:\msys64\clang64\bin\libclang-cpp.dll+0x84099b)
#30 0x00007ffc8ef80422 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (C:\msys64\clang64\bin\libclang-cpp.dll+0x840422)
#31 0x00007ff65b52442d cc1_main(llvm::ArrayRef, char const*, void*) (C:\msys64\clang64\bin\clang++.exe+0x442d)
#32 0x00007ff65b523c06 llvm::raw_ostream::operator<<(llvm::StringRef) (C:\msys64\clang64\bin\clang++.exe+0x3c06)
#33 0x00007ffc9027e7ed void std::__1::vector, std::__1::allocator>>, std::__1::allocator, std::__1::allocator>>>>::__assign_with_size[abi:nn210108], std::__1::allocator>>*, std::__1::optional, std::__1::allocator>>*>(std::__1::optional, std::__1::allocator>>*, std::__1::optional, std::__1::allocator>>*, long long) (C:\msys64\clang64\bin\libclang-cpp.dll+0x1b3e7ed)
#34 0x00007ffbea85bf05 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref) (C:\msys64\clang64\bin\libLLVM-21.dll+0xf1bf05)
#35 0x00007ffc8f0a43b7 clang::driver::CC1Command::Execute(llvm::ArrayRef>, std::__1::basic_string, std::__1::allocator>*, bool*) const (C:\msys64\clang64\bin\libclang-cpp.dll+0x9643b7)
#36 0x00007ffc8f05e153 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (C:\msys64\clang64\bin\libclang-cpp.dll+0x91e153)
#37 0x00007ffc8f05ddd0 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl>&, bool) const (C:\msys64\clang64\bin\libclang-cpp.dll+0x91ddd0)
#38 0x00007ffc8f05dafb clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl>&) (C:\msys64\clang64\bin\libclang-cpp.dll+0x91dafb)
#39 0x00007ff65b521bfc clang_main(int, char**, llvm::ToolContext const&) (C:\msys64\clang64\bin\clang++.exe+0x1bfc)
#40 0x00007ff65b521075 main (C:\msys64\clang64\bin\clang++.exe+0x1075)
#41 0x00007ff65b52a96e WinMainCRTStartup (C:\msys64\clang64\bin\clang++.exe+0xa96e)
#42 0x00007ff65b52ac56 mainCRTStartup (C:\msys64\clang64\bin\clang++.exe+0xac56)
#43 0x00007ffd3adbe8d7 (C:\WINDOWS\System32\KERNEL32.DLL+0x2e8d7)
#44 0x00007ffd3be8c53c (C:\WINDOWS\SYSTEM32\ntdll.dll+0x8c53c)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 21.1.8
Target: x86_64-w64-windows-gnu
Thread model: posix
InstalledDir: C:/msys64/clang64/bin
clang++: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++: note: diagnostic msg: C:/Users/wusik/AppData/Local/Temp/context-0f0fe5.hh
clang++: note: diagnostic msg: C:/Users/wusik/AppData/Local/Temp/context-0f0fe5.sh
clang++: note: diagnostic msg:

********************
```

[context-0f0fe5.sh](https://github.com/user-attachments/files/24912895/context-0f0fe5.sh)

After the crash, clang automatically generated two files:
- context-0f0fe5.sh (run script with full compiler invocation)
- context-0f0fe5.hh (preprocessed source)

I am attaching context-0f0fe5.sh, since it contains the full invocation and flags used to reproduce the issue.
The preprocessed source file (context-0f0fe5.hh) is large (~300k lines, expanded includes and system headers), so I did not attach it by default, but I can provide it if needed.
If you need any further information from my side, please let me know.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.