llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.25k stars 12.08k forks source link

clang-tidy crashing with ACCESS VIOLATION on 17.0.0-rc2 #64602

Open nyyakko opened 1 year ago

nyyakko commented 1 year ago

System: Windows 10 Pro 21H2

clang++:

PS C:\Users\nyako> clang++ --version
clang version 17.0.0
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\Program Files\LLVM\bin

clang-tidy:

PS C:\Users\nyako> clang-tidy --version
LLVM (http://llvm.org/):
  LLVM version 17.0.0-rc2
  Optimized build.

code to reproduce the crash:

template <class T = void>
struct S
{
    auto foo(auto);
};

template <>
auto S<>::foo(auto)
{
    return 1;
}

backtrace:

PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: /clang-tidy <source>
1.  <source>:9:1: current parser token '{'
 #0 0x000000000438c068 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/clang-tidy+0x438c068)
 #1 0x0000000004389c2c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007fda4a7b7420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x0000000003e41d2c clang::Lexer::getRawToken(clang::SourceLocation, clang::Token&, clang::SourceManager const&, clang::LangOptions const&, bool) (/clang-tidy+0x3e41d2c)
 #4 0x0000000003e42dbf clang::Lexer::getLocForEndOfToken(clang::SourceLocation, unsigned int, clang::SourceManager const&, clang::LangOptions const&) (/clang-tidy+0x3e42dbf)
 #5 0x00000000016c0364 (anonymous namespace)::ClangTidyDiagnosticRenderer::emitDiagnosticMessage(clang::FullSourceLoc, clang::PresumedLoc, clang::DiagnosticsEngine::Level, llvm::StringRef, llvm::ArrayRef<clang::CharSourceRange>, llvm::PointerUnion<clang::Diagnostic const*, clang::StoredDiagnostic const*>) ClangTidyDiagnosticConsumer.cpp:0:0
 #6 0x0000000001f56795 clang::DiagnosticRenderer::emitDiagnostic(clang::FullSourceLoc, clang::DiagnosticsEngine::Level, llvm::StringRef, llvm::ArrayRef<clang::CharSourceRange>, llvm::ArrayRef<clang::FixItHint>, llvm::PointerUnion<clang::Diagnostic const*, clang::StoredDiagnostic const*>) (/clang-tidy+0x1f56795)
 #7 0x00000000016c1e63 clang::tidy::ClangTidyDiagnosticConsumer::HandleDiagnostic(clang::DiagnosticsEngine::Level, clang::Diagnostic const&) (/clang-tidy+0x16c1e63)
 #8 0x0000000003f18f2c clang::DiagnosticIDs::ProcessDiag(clang::DiagnosticsEngine&) const (/clang-tidy+0x3f18f2c)
 #9 0x0000000003f0f59b clang::DiagnosticsEngine::EmitCurrentDiagnostic(bool) (/clang-tidy+0x3f0f59b)
#10 0x00000000024d31cf clang::Sema::EmitCurrentDiagnostic(unsigned int) (/clang-tidy+0x24d31cf)
#11 0x00000000024d3bf1 clang::Sema::ImmediateDiagBuilder::~ImmediateDiagBuilder() (/clang-tidy+0x24d3bf1)
#12 0x00000000024d436f clang::Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() (/clang-tidy+0x24d436f)
#13 0x0000000002dc474e clang::Sema::MatchTemplateParametersToScopeSpecifier(clang::SourceLocation, clang::SourceLocation, clang::CXXScopeSpec const&, clang::TemplateIdAnnotation*, llvm::ArrayRef<clang::TemplateParameterList*>, bool, bool&, bool&, bool) (/clang-tidy+0x2dc474e)
#14 0x00000000026e95ac clang::Sema::ActOnFunctionDeclarator(clang::Scope*, clang::Declarator&, clang::DeclContext*, clang::TypeSourceInfo*, clang::LookupResult&, llvm::MutableArrayRef<clang::TemplateParameterList*>, bool&) (/clang-tidy+0x26e95ac)
#15 0x00000000026efb60 clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) (/clang-tidy+0x26efb60)
#16 0x00000000026f0518 clang::Sema::ActOnStartOfFunctionDef(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>, clang::Sema::SkipBodyInfo*, clang::Sema::FnBodyKind) (/clang-tidy+0x26f0518)
#17 0x0000000002212180 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/clang-tidy+0x2212180)
#18 0x00000000023110a7 clang::Parser::ParseSingleDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/clang-tidy+0x23110a7)
#19 0x0000000002318c61 clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/clang-tidy+0x2318c61)
#20 0x0000000002318f23 clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) (/clang-tidy+0x2318f23)
#21 0x00000000022459b0 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) (/clang-tidy+0x22459b0)
#22 0x0000000002214829 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/clang-tidy+0x2214829)
#23 0x00000000022165d5 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/clang-tidy+0x22165d5)
#24 0x0000000002205fca clang::ParseAST(clang::Sema&, bool, bool) (/clang-tidy+0x2205fca)
#25 0x0000000001f5b8b1 clang::FrontendAction::Execute() (/clang-tidy+0x1f5b8b1)
#26 0x0000000001ed8c9b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/clang-tidy+0x1ed8c9b)
#27 0x00000000016fa726 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) (/clang-tidy+0x16fa726)
#28 0x000000000169f82c clang::tidy::runClangTidy(clang::tidy::ClangTidyContext&, clang::tooling::CompilationDatabase const&, llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>, bool, bool, llvm::StringRef)::ActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) ClangTidy.cpp:0:0
#29 0x00000000016f3edc clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr<clang::CompilerInvocation>, std::shared_ptr<clang::PCHContainerOperations>) (/clang-tidy+0x16f3edc)
#30 0x00000000016f70cd clang::tooling::ToolInvocation::run() (/clang-tidy+0x16f70cd)
#31 0x00000000016f8e15 clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (/clang-tidy+0x16f8e15)
#32 0x00000000016a1bd9 clang::tidy::runClangTidy(clang::tidy::ClangTidyContext&, clang::tooling::CompilationDatabase const&, llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>, bool, bool, llvm::StringRef) (/clang-tidy+0x16a1bd9)
#33 0x0000000000a4ca0c clang::tidy::clangTidyMain(int, char const**) (/clang-tidy+0xa4ca0c)
nyyakko commented 1 year ago

as you may have realized, the trace contains information about linux, not windows. this is because i had to reproduce the crash on compiler-explorer so i get clang-tidy to dump useful information. in case you guys still need the trace i got on windows, here you have it:

Error running 'C:/Program Files/LLVM/bin/clang-tidy.exe': PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: "C:/Program Files/LLVM/bin/clang-tidy.exe" --warnings-as-errors=* --extra-arg-before=--driver-mode=g++ C:/Users/nyako/Git/libasync/libasync/source/main.cpp -- C:\\PROGRA~1\\LLVM\\bin\\CLANG_~1.EXE -DFMT_SHARED -IC:/Users/nyako/Git/libasync/libasync/include -IC:/Users/nyako/Git/libasync/libasync/include/libasync -isystem C:/vcpkg/installed/x64-windows/include -O0 -g -Xclang -gcodeview -D_DEBUG -D_DLL -D_MT -Xclang --dependent-lib=msvcrtd -std=gnu++2b -Werror -Wall -Wextra -MD -MT libasync/CMakeFiles/libasync.dir/source/main.cpp.obj -MF libasync\\CMakeFiles\\libasync.dir\\source\\main.cpp.obj.d -o libasync/CMakeFiles/libasync.dir/source/main.cpp.obj -c C:/Users/nyako/Git/libasync/libasync/source/main.cpp
1.      C:\Users\nyako\Git\libasync\libasync\source\main.cpp:141:1: current parser token '{'
Exception Code: 0xC0000005
 #0 0x00007ff6e3779f63 C:\Program Files\LLVM\bin\clang-tidy.exe 0x69f63 C:\Program Files\LLVM\bin\clang-tidy.exe 0x311e2e
 #1 0x00007ff6e3779f63 C:\Program Files\LLVM\bin\clang-tidy.exe 0x313030 C:\Program Files\LLVM\bin\clang-tidy.exe 0x697d7
 #2 0x00007ff6e3779f63 C:\Program Files\LLVM\bin\clang-tidy.exe 0x30d508 C:\Program Files\LLVM\bin\clang-tidy.exe 0x656ef
 #3 0x00007ff6e3779f63 C:\Program Files\LLVM\bin\clang-tidy.exe 0x27cea6 C:\Program Files\LLVM\bin\clang-tidy.exe 0x280976
 #4 0x00007ff6e3779f63 C:\Program Files\LLVM\bin\clang-tidy.exe 0xd49739 C:\Program Files\LLVM\bin\clang-tidy.exe 0xd4a639
 #5 0x00007ff6e3779f63 C:\Program Files\LLVM\bin\clang-tidy.exe 0xd326a9 C:\Program Files\LLVM\bin\clang-tidy.exe 0x1f40c8d
 #6 0x00007ff6e3779f63 C:\Program Files\LLVM\bin\clang-tidy.exe 0x15a4c5e C:\Program Files\LLVM\bin\clang-tidy.exe 0x15a2cc3
 #7 0x00007ff6e3779f63 C:\Program Files\LLVM\bin\clang-tidy.exe 0x15c0185 C:\Program Files\LLVM\bin\clang-tidy.exe 0x1a6889d
 #8 0x00007ff6e3779f63 C:\Program Files\LLVM\bin\clang-tidy.exe 0x2128933 C:\Program Files\LLVM\bin\clang-tidy.exe 0x212696f
 #9 0x00007ff6e3779f63 C:\Program Files\LLVM\bin\clang-tidy.exe 0x212627e C:\Program Files\LLVM\bin\clang-tidy.exe 0x210a5ee
#10 0x00007ff6e3779f63 C:\Program Files\LLVM\bin\clang-tidy.exe 0x1a65bbc C:\Program Files\LLVM\bin\clang-tidy.exe 0x1a64098
#11 0x00007ff6e3779f63 C:\Program Files\LLVM\bin\clang-tidy.exe 0xd7746e C:\Program Files\LLVM\bin\clang-tidy.exe 0x2dc2f2
#12 0x00007ff6e3779f63 C:\Program Files\LLVM\bin\clang-tidy.exe 0xac54ad C:\Program Files\LLVM\bin\clang-tidy.exe 0x2868bc
#13 0x00007ff6e3779f63 C:\Program Files\LLVM\bin\clang-tidy.exe 0x55097 C:\Program Files\LLVM\bin\clang-tidy.exe 0x286780
#14 0x00007ff6e3779f63 C:\Program Files\LLVM\bin\clang-tidy.exe 0x285336 C:\Program Files\LLVM\bin\clang-tidy.exe 0x287ff7
#15 0x00007ff6e3779f63 C:\Program Files\LLVM\bin\clang-tidy.exe 0x4f741 C:\Program Files\LLVM\bin\clang-tidy.exe 0x65e6
#16 0x00007ff6e3779f63 C:\Program Files\LLVM\bin\clang-tidy.exe 0x21cd5b0 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x69f63)
#17 0x00007ff6e3779f63 
#18 0x00007ff6e3779f63 (C:\Program Files\LLVM\bin\clang-tidy.exe+0x69f63)
0x00007FF6E3779F63, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x69F63 byte(s)
0x00007FF6E3A21E2E, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x311E2E byte(s)
0x00007FF6E3A23030, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x313030 byte(s)
0x00007FF6E37797D7, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x697D7 byte(s)
0x00007FF6E3A1D508, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x30D508 byte(s)
0x00007FF6E37756EF, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x656EF byte(s)
0x00007FF6E398CEA6, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x27CEA6 byte(s)
0x00007FF6E3990976, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x280976 byte(s)
0x00007FF6E4459739, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0xD49739 byte(s)
0x00007FF6E445A639, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0xD4A639 byte(s)
0x00007FF6E44426A9, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0xD326A9 byte(s)
0x00007FF6E5650C8D, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x1F40C8D byte(s)
0x00007FF6E4CB4C5E, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x15A4C5E byte(s)
0x00007FF6E4CB2CC3, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x15A2CC3 byte(s)
0x00007FF6E4CD0185, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x15C0185 byte(s)
0x00007FF6E517889D, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x1A6889D byte(s)
0x00007FF6E5838933, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x2128933 byte(s)
0x00007FF6E583696F, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x212696F byte(s)
0x00007FF6E583627E, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x212627E byte(s)
0x00007FF6E581A5EE, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x210A5EE byte(s)
0x00007FF6E5175BBC, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x1A65BBC byte(s)
0x00007FF6E5174098, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x1A64098 byte(s)
0x00007FF6E448746E, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0xD7746E byte(s)
0x00007FF6E39EC2F2, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x2DC2F2 byte(s)
0x00007FF6E41D54AD, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0xAC54AD byte(s)
0x00007FF6E39968BC, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x2868BC byte(s)
0x00007FF6E3765097, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x55097 byte(s)
0x00007FF6E3996780, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x286780 byte(s)
0x00007FF6E3995336, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x285336 byte(s)
0x00007FF6E3997FF7, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x287FF7 byte(s)
0x00007FF6E375F741, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x4F741 byte(s)
0x00007FF6E37165E6, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x65E6 byte(s)
0x00007FF6E58DD5B0, C:\Program Files\LLVM\bin\clang-tidy.exe(0x00007FF6E3710000) + 0x21CD5B0 byte(s)
0x00007FFA4DC67614, C:\Windows\System32\KERNEL32.DLL(0x00007FFA4DC50000) + 0x17614 byte(s), BaseThreadInitThunk() + 0x14 byte(s)
0x00007FFA4EAC26F1, C:\Windows\SYSTEM32\ntdll.dll(0x00007FFA4EA70000) + 0x526F1 byte(s), RtlUserThreadStart() + 0x21 byte(s)
Access violation
llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-tidy

EugeneZelenko commented 1 year ago

Could you please narrow down problem to particular check?

danix800 commented 1 year ago

Confirmed. Not checker related. Reproducible with clang-tidy test.cpp -- -std=gnu++2b on linux.

danix800 commented 1 year ago

Full stack dump:

clang-tidy: /home/xxxxx/Sources/llvm-project-main/clang/include/clang/Basic/SourceLocation.h:383: const clang::SourceManager &clang::FullSourceLoc::getManager() const: Assertion `SrcMgr && "SourceManager is NULL."' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: /home/xxxxx/Sources/llvm-project-main/build/bin/clang-tidy test.cpp -- -std=gnu++2b
1.  /home/xxxxx/test.cpp:9:1: current parser token '{'
 #0 0x00007f3eccbf812a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/xxxxx/Sources/llvm-project-main/llvm/lib/Support/Unix/Signals.inc:602:11
 #1 0x00007f3eccbf82db PrintStackTraceSignalHandler(void*) /home/xxxxx/Sources/llvm-project-main/llvm/lib/Support/Unix/Signals.inc:675:1
 #2 0x00007f3eccbf6846 llvm::sys::RunSignalHandlers() /home/xxxxx/Sources/llvm-project-main/llvm/lib/Support/Signals.cpp:104:5
 #3 0x00007f3eccbf8af5 SignalHandler(int) /home/xxxxx/Sources/llvm-project-main/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x00007f3ecf116fd0 (/lib/x86_64-linux-gnu/libc.so.6+0x3bfd0)
 #5 0x00007f3ecf165d3c __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #6 0x00007f3ecf116f32 raise ./signal/../sysdeps/posix/raise.c:27:6
 #7 0x00007f3ecf101472 abort ./stdlib/abort.c:81:7
 #8 0x00007f3ecf101395 _nl_load_domain ./intl/loadmsgcat.c:1177:9
 #9 0x00007f3ecf10fe32 (/lib/x86_64-linux-gnu/libc.so.6+0x34e32)
#10 0x00007f3ecf5af962 clang::FullSourceLoc::getManager() const /home/xxxxx/Sources/llvm-project-main/clang/include/clang/Basic/SourceLocation.h:0:5
#11 0x00007f3ecf59fe64 (anonymous namespace)::ClangTidyDiagnosticRenderer::emitDiagnosticMessage(clang::FullSourceLoc, clang::PresumedLoc, clang::DiagnosticsEngine::Level, llvm::StringRef, llvm::ArrayRef<clang::CharSourceRange>, llvm::PointerUnion<clang::Diagnostic const*, clang::StoredDiagnostic const*>) /home/xxxxx/Sources/llvm-project-main/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:102:45
#12 0x00007f3ec6f6afa2 clang::DiagnosticRenderer::emitDiagnostic(clang::FullSourceLoc, clang::DiagnosticsEngine::Level, llvm::StringRef, llvm::ArrayRef<clang::CharSourceRange>, llvm::ArrayRef<clang::FixItHint>, llvm::PointerUnion<clang::Diagnostic const*, clang::StoredDiagnostic const*>) /home/xxxxx/Sources/llvm-project-main/clang/lib/Frontend/DiagnosticRenderer.cpp:98:5
#13 0x00007f3ecf59dce2 clang::tidy::ClangTidyDiagnosticConsumer::HandleDiagnostic(clang::DiagnosticsEngine::Level, clang::Diagnostic const&) /home/xxxxx/Sources/llvm-project-main/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:444:3
#14 0x00007f3ecd3e5032 clang::DiagnosticIDs::EmitDiag(clang::DiagnosticsEngine&, clang::DiagnosticIDs::Level) const /home/xxxxx/Sources/llvm-project-main/clang/lib/Basic/DiagnosticIDs.cpp:824:7
#15 0x00007f3ecd3e4e74 clang::DiagnosticIDs::ProcessDiag(clang::DiagnosticsEngine&) const /home/xxxxx/Sources/llvm-project-main/clang/lib/Basic/DiagnosticIDs.cpp:816:3
#16 0x00007f3ecd3d5659 clang::DiagnosticsEngine::ProcessDiag() /home/xxxxx/Sources/llvm-project-main/clang/include/clang/Basic/Diagnostic.h:1037:5
#17 0x00007f3ecd3d04a9 clang::DiagnosticsEngine::EmitCurrentDiagnostic(bool) /home/xxxxx/Sources/llvm-project-main/clang/lib/Basic/Diagnostic.cpp:545:13
#18 0x00007f3ec52e727d clang::Sema::EmitCurrentDiagnostic(unsigned int) /home/xxxxx/Sources/llvm-project-main/clang/lib/Sema/Sema.cpp:1599:7
#19 0x00007f3ec52f9ee6 clang::Sema::ImmediateDiagBuilder::~ImmediateDiagBuilder() /home/xxxxx/Sources/llvm-project-main/clang/include/clang/Sema/Sema.h:1755:5
#20 0x00007f3ec5319ff9 std::_Optional_payload_base<clang::Sema::ImmediateDiagBuilder>::_M_destroy() /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/optional:288:7
#21 0x00007f3ec5319fb7 std::_Optional_payload_base<clang::Sema::ImmediateDiagBuilder>::_M_reset() /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/optional:319:7
#22 0x00007f3ec533e595 std::_Optional_base_impl<clang::Sema::ImmediateDiagBuilder, std::_Optional_base<clang::Sema::ImmediateDiagBuilder, false, false>>::_M_reset() /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/optional:468:57
#23 0x00007f3ec52fa095 std::optional<clang::Sema::ImmediateDiagBuilder>::reset() /usr/bin/../lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/optional:1170:70
#24 0x00007f3ec52e7a56 clang::Sema::SemaDiagnosticBuilder::~SemaDiagnosticBuilder() /home/xxxxx/Sources/llvm-project-main/clang/lib/Sema/Sema.cpp:1883:26
#25 0x00007f3ec6460c61 clang::Sema::MatchTemplateParametersToScopeSpecifier(clang::SourceLocation, clang::SourceLocation, clang::CXXScopeSpec const&, clang::TemplateIdAnnotation*, llvm::ArrayRef<clang::TemplateParameterList*>, bool, bool&, bool&, bool) /home/xxxxx/Sources/llvm-project-main/clang/lib/Sema/SemaTemplate.cpp:3491:11
#26 0x00007f3ec57d50fe clang::Sema::ActOnFunctionDeclarator(clang::Scope*, clang::Declarator&, clang::DeclContext*, clang::TypeSourceInfo*, clang::LookupResult&, llvm::MutableArrayRef<clang::TemplateParameterList*>, bool&) /home/xxxxx/Sources/llvm-project-main/clang/lib/Sema/SemaDecl.cpp:9856:28
#27 0x00007f3ec57d3484 clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) /home/xxxxx/Sources/llvm-project-main/clang/lib/Sema/SemaDecl.cpp:6499:9
#28 0x00007f3ec57f4b6d clang::Sema::ActOnStartOfFunctionDef(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>, clang::Sema::SkipBodyInfo*, clang::Sema::FnBodyKind) /home/xxxxx/Sources/llvm-project-main/clang/lib/Sema/SemaDecl.cpp:15147:14
#29 0x00007f3ebfa4aef0 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) /home/xxxxx/Sources/llvm-project-main/clang/lib/Parse/Parser.cpp:1399:9
#30 0x00007f3ebfa32ec9 clang::Parser::ParseSingleDeclarationAfterTemplate(clang::DeclaratorContext, clang::Parser::ParsedTemplateInfo const&, clang::ParsingDeclRAIIObject&, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) /home/xxxxx/Sources/llvm-project-main/clang/lib/Parse/ParseTemplate.cpp:361:5
#31 0x00007f3ebfa318bf clang::Parser::ParseTemplateDeclarationOrSpecialization(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) /home/xxxxx/Sources/llvm-project-main/clang/lib/Parse/ParseTemplate.cpp:171:3
#32 0x00007f3ebfa31284 clang::Parser::ParseDeclarationStartingWithTemplate(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::AccessSpecifier) /home/xxxxx/Sources/llvm-project-main/clang/lib/Parse/ParseTemplate.cpp:48:3
#33 0x00007f3ebf90b8a4 clang::Parser::ParseDeclaration(clang::DeclaratorContext, clang::SourceLocation&, clang::ParsedAttributes&, clang::ParsedAttributes&, clang::SourceLocation*) /home/xxxxx/Sources/llvm-project-main/clang/lib/Parse/ParseDecl.cpp:1846:16
#34 0x00007f3ebfa489a7 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) /home/xxxxx/Sources/llvm-project-main/clang/lib/Parse/Parser.cpp:956:14
#35 0x00007f3ebfa46dcc clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /home/xxxxx/Sources/llvm-project-main/clang/lib/Parse/Parser.cpp:742:12
#36 0x00007f3ebf8ea927 clang::ParseAST(clang::Sema&, bool, bool) /home/xxxxx/Sources/llvm-project-main/clang/lib/Parse/ParseAST.cpp:163:16
#37 0x00007f3ec6f7868c clang::ASTFrontendAction::ExecuteAction() /home/xxxxx/Sources/llvm-project-main/clang/lib/Frontend/FrontendAction.cpp:1175:1
#38 0x00007f3ec6f7808c clang::FrontendAction::Execute() /home/xxxxx/Sources/llvm-project-main/clang/lib/Frontend/FrontendAction.cpp:1067:7
#39 0x00007f3ec6e82ba8 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /home/xxxxx/Sources/llvm-project-main/clang/lib/Frontend/CompilerInstance.cpp:1054:23
#40 0x00007f3ecf41ff93 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) /home/xxxxx/Sources/llvm-project-main/clang/lib/Tooling/Tooling.cpp:467:14
#41 0x00007f3ecf532589 clang::tidy::runClangTidy(clang::tidy::ClangTidyContext&, clang::tooling::CompilationDatabase const&, llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>, bool, bool, llvm::StringRef)::ActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) /home/xxxxx/Sources/llvm-project-main/clang-tools-extra/clang-tidy/ClangTidy.cpp:565:37
#42 0x00007f3ecf41fe31 clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr<clang::CompilerInvocation>, std::shared_ptr<clang::PCHContainerOperations>) /home/xxxxx/Sources/llvm-project-main/clang/lib/Tooling/Tooling.cpp:442:18
#43 0x00007f3ecf41eecd clang::tooling::ToolInvocation::run() /home/xxxxx/Sources/llvm-project-main/clang/lib/Tooling/Tooling.cpp:427:3
#44 0x00007f3ecf42112e clang::tooling::ClangTool::run(clang::tooling::ToolAction*) /home/xxxxx/Sources/llvm-project-main/clang/lib/Tooling/Tooling.cpp:619:11
#45 0x00007f3ecf53007c clang::tidy::runClangTidy(clang::tidy::ClangTidyContext&, clang::tooling::CompilationDatabase const&, llvm::ArrayRef<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>, bool, bool, llvm::StringRef) /home/xxxxx/Sources/llvm-project-main/clang-tools-extra/clang-tidy/ClangTidy.cpp:586:8
#46 0x00007f3ed5949eaf clang::tidy::clangTidyMain(int, char const**) /home/xxxxx/Sources/llvm-project-main/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp:676:7
#47 0x000055bba390c312 main /home/xxxxx/Sources/llvm-project-main/clang-tools-extra/clang-tidy/tool/ClangTidyToolMain.cpp:20:3
#48 0x00007f3ecf1021ca __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#49 0x00007f3ecf102285 call_init ./csu/../csu/libc-start.c:128:20
#50 0x00007f3ecf102285 __libc_start_main ./csu/../csu/libc-start.c:347:5
#51 0x000055bba390c221 _start (/home/xxxxx/Sources/llvm-project-main/build/bin/clang-tidy+0x2221)
AaronBallman commented 1 year ago

Can confirm: https://godbolt.org/z/1r6EeoTcK

PiotrZSL commented 1 year ago

Looks like there are 2 problems:

  1. Diagnostic is raised with invalid location (issue in clang frontend):
    clang++ 1.cpp -std=c++20
    error: template parameter list matching the non-templated nested type 'S<>' should be empty ('template<>')
    1 error generated.
  2. Clang tidy does not handle well such warnings, by still trying to read SourceManager from invalid location.
PiotrZSL commented 1 year ago

https://reviews.llvm.org/D157649

AaronBallman commented 1 year ago
  1. Diagnostic is raised with invalid location (issue in clang frontend):
clang++ 1.cpp -std=c++20
error: template parameter list matching the non-templated nested type 'S<>' should be empty ('template<>')
1 error generated.

Good catch -- that's a Clang bug.

AaronBallman commented 1 year ago

I tracked the issue down to here: https://github.com/llvm/llvm-project/blob/afff91de082d1347d81c413a424f0a1b6fb02774/clang/lib/Sema/SemaDeclCXX.cpp#L19013

I think this should probably be using Declarator.getBeginLoc() instead of SourceLocation() so that we get a valid location somewhere near the declarator. WDYT @erichkeane?

llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-frontend