llvm / llvm-project

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

clang-tidy crash when cppcoreguidelines checks with objectivec++ file #65105

Open JerryMu opened 1 year ago

JerryMu commented 1 year ago

I'm using llvm 16.08 with c++20. Clangd keeps crashing when enabling clang-tidy cppcoreguidelines with the objectivec++(.mm) file.
More specific clang-tidy crashes when there is any @implementation in the code file.

I[16:41:32.023] Indexing c++20 standard library in the context of /Users/bob/work/WorkProjects/cRollBall/proj.ios_mac/mac/mac_tools/configEdit/configEditorObjController.mm I[16:41:33.443] Built preamble of size 65731884 for file /Users/bob/work/WorkProjects/cRollBall/proj.ios_mac/mac/mac_tools/configEdit/configEditorObjController.mm version 16 in 5.60 seconds I[16:41:33.446] --> @workspace/semanticTokens/refresh(1) I[16:41:33.448] <-- reply(1) I[16:41:33.474] getStyle() failed for file /Users/bob/work/WorkProjects/cRollBall/proj.ios_mac/mac/mac_tools/configEdit/configEditorObjController.mm: Configuration file(s) do(es) not support Objective-C: /Users/bob/work/WorkProjects/cRollBall/.clang-format. Fallback is LLVM style. 0 libLLVM.dylib 0x000000011b5d22bb llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 43 1 libLLVM.dylib 0x000000011fc03678 SignalHandler(int) + 184 2 libsystem_platform.dylib 0x00007ff80ea01c1d _sigtramp + 29 3 libsystem_platform.dylib 0x0000000000000060 _sigtramp + 18446603370335560800 4 clangd 0x0000000107bdb851 clang::ast_matchers::internal::DynTypedMatcher::matches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const + 561 5 clangd 0x0000000107bdeb34 clang::ast_matchers::internal::(anonymous namespace)::VariadicMatcher<&clang::ast_matchers::internal::notUnaryOperator(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*, llvm::ArrayRef<clang::ast_matchers::internal::DynTypedMatcher>)>::dynMatches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const + 116 6 clangd 0x0000000107bde1cf clang::ast_matchers::internal::(anonymous namespace)::VariadicMatcher<&clang::ast_matchers::internal::allOfVariadicOperator(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*, llvm::ArrayRef<clang::ast_matchers::internal::DynTypedMatcher>)>::dynMatches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const + 447 7 clangd 0x0000000107bddb11 clang::ast_matchers::internal::(anonymous namespace)::IdDynMatcher::dynMatches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const + 33 8 clangd 0x0000000107bdb851 clang::ast_matchers::internal::DynTypedMatcher::matches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const + 561 9 clangd 0x0000000107bc631c clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchWithFilter(clang::DynTypedNode const&) + 1820 10 clangd 0x0000000107bc7869 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) + 217 11 clangd 0x0000000107bca1de clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) + 10830 12 clangd 0x0000000107bcbaa0 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) + 17168 13 clangd 0x0000000107bb10f8 clang::ast_matchers::MatchFinder::matchAST(clang::ASTContext&) + 632 14 clangd 0x000000010761d40d clang::clangd::ParsedAST::build(llvm::StringRef, clang::clangd::ParseInputs const&, std::__1::unique_ptr<clang::CompilerInvocation, std::__1::default_delete<clang::CompilerInvocation>>, llvm::ArrayRef<clang::clangd::Diag>, std::__1::shared_ptr<clang::clangd::PreambleData const>) + 14333 15 clangd 0x00000001076a0cf9 clang::clangd::(anonymous namespace)::ASTWorker::updatePreamble(std::__1::unique_ptr<clang::CompilerInvocation, std::__1::default_delete<clang::CompilerInvocation>>, clang::clangd::ParseInputs, std::__1::shared_ptr<clang::clangd::PreambleData const>, std::__1::vector<clang::clangd::Diag, std::__1::allocator<clang::clangd::Diag>>, clang::clangd::WantDiagnostics)::$_0::operator()() + 1593 16 clangd 0x000000010769c432 clang::clangd::(anonymous namespace)::ASTWorker::runTask(llvm::StringRef, llvm::function_ref<void ()>) + 482 17 clangd 0x00000001076994d4 void llvm::detail::UniqueFunctionBase<void>::CallImpl<clang::clangd::(anonymous namespace)::ASTWorker::create(llvm::StringRef, clang::clangd::GlobalCompilationDatabase const&, clang::clangd::TUScheduler::ASTCache&, clang::clangd::TUScheduler::HeaderIncluderCache&, clang::clangd::AsyncTaskRunner*, clang::clangd::Semaphore&, clang::clangd::TUScheduler::Options const&, clang::clangd::ParsingCallbacks&)::$_0>(void*) + 3380 18 clangd 0x0000000107833586 void* llvm::thread::ThreadProxy<std::__1::tuple<clang::clangd::AsyncTaskRunner::runAsync(llvm::Twine const&, llvm::unique_function<void ()>)::$_1>>(void*) + 70 19 libsystem_pthread.dylib 0x00007ff80e9d7259 _pthread_start + 125 20 libsystem_pthread.dylib 0x00007ff80e9d2c7b thread_start + 15

PiotrZSL commented 1 year ago

This is clangd binary, not clang-tidy. Do you know some specific check name that crashes ? Most probably sufficient would be to make sure that all cppcoreguidelines checks got set C/C++ as an required language.

llvmbot commented 1 year ago

@llvm/issue-subscribers-clangd

llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-tidy

HighCommander4 commented 1 year ago

@JerryMu could you provide an example code file that triggers the crash?

JerryMu commented 1 year ago
---
Checks: "
-*,
bugprone-*,
performance-*,
readability-*,
misc-*,

modernize-*,
-modernize-use-trailing-return-type,

cppcoreguidelines-*  
"
---

.Clang-tidy file above with with A simple objective-c source file below is enough trigger this crash.

#import "AppController.h"
@implementation AppController

@end
sam-mccall commented 1 year ago

Could you provide a complete source file that doesn't include external headers?

JerryMu commented 1 year ago

I found this crash only occurs with specific header and source file combinations.
This example only includes system headers. I found @property(nonatomic, readonly) NSViewController *viewController; is part of the reason, combining it with @implementation in the source file will trigger this crash. CrashTest.h

#include <AppKit/AppKit.h>

@interface CrashTest {
}
@property(nonatomic, readonly) NSViewController *viewController;

@end

CrashTest.mm


#import "CrashTest.h"

@implementation CrashTest

@end
thomas-brandstaetter commented 11 months ago

Same issue here:

b@10 ninja-Debug % clang-tidy --version
LLVM (http://llvm.org/):
  LLVM version 16.0.6
  Optimized build.

Goal:

Run clang-tidy on an objective-c++ file with -checks="*"

File under Test:

#import <Cocoa/Cocoa.h>

int main(int argc, const char **argv) {
    return NSApplicationMain(argc, argv);
}

Invocation and result:

b@10 ninja-Debug % clang-tidy -checks="*"  -p ./ ../../xxx/source/main.mm
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.  Program arguments: /opt/local/libexec/llvm-16/bin/clang-tidy -checks=* -p ./ ../../xxx/source/main.mm
1.  <eof> parser at end of file
2.  ASTMatcher: Matching 'cppcoreguidelines-avoid-const-or-ref-data-members' against:
    ObjCIvarDecl NSObject::isa : </Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/objc/NSObject.h:56:5, col:11>
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.dylib            0x00000001210ed317 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 39
1  libLLVM.dylib            0x00000001210ec268 llvm::sys::RunSignalHandlers() + 248
2  libLLVM.dylib            0x00000001210ed960 SignalHandler(int) + 272
3  libsystem_platform.dylib 0x00007ff80c27b5ed _sigtramp + 29
4  libsystem_platform.dylib 000000000000000000 _sigtramp + 18446603370377005616
5  clang-tidy               0x000000011061f81f clang::ast_matchers::internal::DynTypedMatcher::matches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const + 255
6  clang-tidy               0x0000000110623592 clang::ast_matchers::internal::(anonymous namespace)::VariadicMatcher<&clang::ast_matchers::internal::notUnaryOperator(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*, llvm::ArrayRef<clang::ast_matchers::internal::DynTypedMatcher>)>::dynMatches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const + 114
7  clang-tidy               0x000000011061f99e clang::ast_matchers::internal::DynTypedMatcher::matchesNoKindCheck(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const + 238
8  clang-tidy               0x0000000110622681 clang::ast_matchers::internal::(anonymous namespace)::VariadicMatcher<&clang::ast_matchers::internal::allOfVariadicOperator(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*, llvm::ArrayRef<clang::ast_matchers::internal::DynTypedMatcher>)>::dynMatches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const + 113
9  clang-tidy               0x0000000110622121 clang::ast_matchers::internal::(anonymous namespace)::IdDynMatcher::dynMatches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const + 33
10 clang-tidy               0x000000011061f81f clang::ast_matchers::internal::DynTypedMatcher::matches(clang::DynTypedNode const&, clang::ast_matchers::internal::ASTMatchFinder*, clang::ast_matchers::internal::BoundNodesTreeBuilder*) const + 255
11 clang-tidy               0x00000001105e9806 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchWithFilter(clang::DynTypedNode const&) + 1398
12 clang-tidy               0x00000001105ec43c clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) + 236
13 clang-tidy               0x00000001105eedab clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseObjCInterfaceDecl(clang::ObjCInterfaceDecl*) + 443
14 clang-tidy               0x00000001105ec5e7 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) + 663
15 clang-tidy               0x00000001105ede8b clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseLinkageSpecDecl(clang::LinkageSpecDecl*) + 59
16 clang-tidy               0x00000001105ec537 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) + 487
17 clang-tidy               0x00000001105f4f3b clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseTranslationUnitDecl(clang::TranslationUnitDecl*) + 475
18 clang-tidy               0x00000001105ec9ac clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) + 1628
19 clang-tidy               0x00000001105ba739 clang::ast_matchers::MatchFinder::matchAST(clang::ASTContext&) + 809
20 libclang-cpp.dylib       0x00000001178e281c clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) + 44
21 libclang-cpp.dylib       0x0000000115a504fd clang::ParseAST(clang::Sema&, bool, bool) + 829
22 libclang-cpp.dylib       0x00000001178a475a clang::FrontendAction::Execute() + 90
23 libclang-cpp.dylib       0x000000011781dcc6 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 822
24 libclang-cpp.dylib       0x0000000117ad759e clang::tooling::FrontendActionFactory::runInvocation(std::__1::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::__1::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) + 286
25 clang-tidy               0x000000010ffb47d5 clang::tidy::runClangTidy(clang::tidy::ClangTidyContext&, clang::tooling::CompilationDatabase const&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>, bool, bool, llvm::StringRef)::ActionFactory::runInvocation(std::__1::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::__1::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) + 85
26 libclang-cpp.dylib       0x0000000117ad7401 clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::__1::shared_ptr<clang::CompilerInvocation>, std::__1::shared_ptr<clang::PCHContainerOperations>) + 257
27 libclang-cpp.dylib       0x0000000117ad5b7f clang::tooling::ToolInvocation::run() + 1775
28 libclang-cpp.dylib       0x0000000117ad8d29 clang::tooling::ClangTool::run(clang::tooling::ToolAction*) + 3753
29 clang-tidy               0x000000010ffafc54 clang::tidy::runClangTidy(clang::tidy::ClangTidyContext&, clang::tooling::CompilationDatabase const&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>, llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem>, bool, bool, llvm::StringRef) + 1060
30 clang-tidy               0x000000010ffe4549 clang::tidy::clangTidyMain(int, char const**) + 10361
31 dyld                     0x00007ff80bef441f start + 1903
zsh: segmentation fault  clang-tidy -checks="*" -p ./ ../../xxx/source/main.mm