Skip to content

A/F: `isInstance() && "No 'this' for static methods!"' in clang-tidy after commit 2c6424e691 #117005

Closed
@dyung

Description

@dyung

Recently one of our internal tests started to see an assertion failure in clang-tidy which I bisected back to 2c6424e.

Consider the following code:

struct A {
  static void b();
};

When this code is run through clang-tidy that includes 2c6424e, it hits an assertion failure:

$ ~/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bin/clang-tidy test.cpp
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "test.cpp"
No compilation database found in /home/dyung/sandbox/repro10 or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
clang-tidy: /home/dyung/src/upstream/llvm_clean_git/clang/lib/AST/DeclCXX.cpp:2661: clang::QualType clang::CXXMethodDecl::getThisType() const: Assertion `isInstance() && "No 'this' for static methods!"' 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/dyung/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bin/clang-tidy test.cpp
1.      <eof> parser at end of file
 #0 0x000055e2f401f58f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/dyung/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bin/clang-tidy+0x4f6158f)
 #1 0x000055e2f401cae4 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f742edd5420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f742e8a800b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #4 0x00007f742e887859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
 #5 0x00007f742e887729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
 #6 0x00007f742e887729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
 #7 0x00007f742e898fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #8 0x000055e2f2c27483 clang::CXXMethodDecl::getThisType() const (/home/dyung/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bin/clang-tidy+0x3b69483)
 #9 0x000055e2f0e6334d clang::RecursiveASTVisitor<(anonymous namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) const::LocalVisitor>::TraverseDecl(clang::Decl*) (.part.0) UncountedLambdaCapture
sChecker.cpp:0:0
#10 0x000055e2f0e64223 clang::RecursiveASTVisitor<(anonymous namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) const::LocalVisitor>::TraverseDeclContextHelper(clang::DeclContext*) (.part.0) Un
countedLambdaCapturesChecker.cpp:0:0
#11 0x000055e2f0e62b59 clang::RecursiveASTVisitor<(anonymous namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) const::LocalVisitor>::TraverseDecl(clang::Decl*) (.part.0) UncountedLambdaCapture
sChecker.cpp:0:0
#12 0x000055e2f0e64223 clang::RecursiveASTVisitor<(anonymous namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) const::LocalVisitor>::TraverseDeclContextHelper(clang::DeclContext*) (.part.0) Un
countedLambdaCapturesChecker.cpp:0:0
#13 0x000055e2f0e87119 clang::RecursiveASTVisitor<(anonymous namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) const::LocalVisitor>::TraverseTranslationUnitDecl(clang::TranslationUnitDecl*) Un
countedLambdaCapturesChecker.cpp:0:0
#14 0x000055e2f0e8a11d void clang::ento::check::ASTDecl<clang::TranslationUnitDecl>::_checkDecl<(anonymous namespace)::UncountedLambdaCapturesChecker>(void*, clang::Decl const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) UncountedLambdaCapturesChecker.cpp:0:0
#15 0x000055e2f0f58aa1 clang::ento::CheckerManager::runCheckersOnASTDecl(clang::Decl const*, clang::ento::AnalysisManager&, clang::ento::BugReporter&) (/home/dyung/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bin/clang-tidy+0x1e9aaa1)
#16 0x000055e2f09623de (anonymous namespace)::AnalysisConsumer::HandleTranslationUnit(clang::ASTContext&) AnalysisConsumer.cpp:0:0
#17 0x000055e2f12a7b20 clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) (/home/dyung/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bin/clang-tidy+0x21e9b20)
#18 0x000055e2f156c76c clang::ParseAST(clang::Sema&, bool, bool) (/home/dyung/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bin/clang-tidy+0x24ae76c)
#19 0x000055e2f12669d9 clang::FrontendAction::Execute() (/home/dyung/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bin/clang-tidy+0x21a89d9)
#20 0x000055e2f11db81e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/home/dyung/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bin/clang-tidy+0x211d81e)
#21 0x000055e2f0928b30 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) (/home/dyung/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bi
n/clang-tidy+0x186ab30)
#22 0x000055e2f08c6869 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, llv
m::StringRef)::ActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) ClangTidy.cpp:0:0
#23 0x000055e2f091faa7 clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr<clang::CompilerInvocation>, std::shared_ptr<clang::PCHContainerOperations>) (/home/dyung/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bin/clang-tidy+0
x1861aa7)
#24 0x000055e2f0923358 clang::tooling::ToolInvocation::run() (/home/dyung/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bin/clang-tidy+0x1865358)
#25 0x000055e2f0926a41 clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (/home/dyung/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bin/clang-tidy+0x1868a41)
#26 0x000055e2f08d8356 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, llv
m::StringRef) (/home/dyung/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bin/clang-tidy+0x181a356)
#27 0x000055e2efe6d86a clang::tidy::clangTidyMain(int, char const**) (/home/dyung/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bin/clang-tidy+0xdaf86a)
#28 0x00007f742e889083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#29 0x000055e2efe6379e _start (/home/dyung/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bin/clang-tidy+0xda579e)
Aborted (core dumped)

A clang-tidy built from the parent commit does not hit an assertion failure:

$ ~/src/upstream/06e08696248ac01754c87c22cc8a4b797ef46430-linux/bin/clang-tidy test.cpp
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "test.cpp"
No compilation database found in /home/dyung/sandbox/repro10 or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions