Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dyung opened this issue Nov 20, 2024 · 7 comments
Labels
clang:static analyzer crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@dyung
Copy link
Collaborator

dyung commented Nov 20, 2024

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.
@llvmbot
Copy link
Member

llvmbot commented Nov 20, 2024

@llvm/issue-subscribers-clang-static-analyzer

Author: None (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() &amp;&amp; "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.      &lt;eof&gt; parser at end of file
 #<!-- -->0 0x000055e2f401f58f llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, 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&lt;(anonymous namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl const*, clang::ento::AnalysisManager&amp;, clang::ento::BugReporter&amp;) const::LocalVisitor&gt;::TraverseDecl(clang::Decl*) (.part.0) UncountedLambdaCapture
sChecker.cpp:0:0
#<!-- -->10 0x000055e2f0e64223 clang::RecursiveASTVisitor&lt;(anonymous namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl const*, clang::ento::AnalysisManager&amp;, clang::ento::BugReporter&amp;) const::LocalVisitor&gt;::TraverseDeclContextHelper(clang::DeclContext*) (.part.0) Un
countedLambdaCapturesChecker.cpp:0:0
#<!-- -->11 0x000055e2f0e62b59 clang::RecursiveASTVisitor&lt;(anonymous namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl const*, clang::ento::AnalysisManager&amp;, clang::ento::BugReporter&amp;) const::LocalVisitor&gt;::TraverseDecl(clang::Decl*) (.part.0) UncountedLambdaCapture
sChecker.cpp:0:0
#<!-- -->12 0x000055e2f0e64223 clang::RecursiveASTVisitor&lt;(anonymous namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl const*, clang::ento::AnalysisManager&amp;, clang::ento::BugReporter&amp;) const::LocalVisitor&gt;::TraverseDeclContextHelper(clang::DeclContext*) (.part.0) Un
countedLambdaCapturesChecker.cpp:0:0
#<!-- -->13 0x000055e2f0e87119 clang::RecursiveASTVisitor&lt;(anonymous namespace)::UncountedLambdaCapturesChecker::checkASTDecl(clang::TranslationUnitDecl const*, clang::ento::AnalysisManager&amp;, clang::ento::BugReporter&amp;) const::LocalVisitor&gt;::TraverseTranslationUnitDecl(clang::TranslationUnitDecl*) Un
countedLambdaCapturesChecker.cpp:0:0
#<!-- -->14 0x000055e2f0e8a11d void clang::ento::check::ASTDecl&lt;clang::TranslationUnitDecl&gt;::_checkDecl&lt;(anonymous namespace)::UncountedLambdaCapturesChecker&gt;(void*, clang::Decl const*, clang::ento::AnalysisManager&amp;, clang::ento::BugReporter&amp;) UncountedLambdaCapturesChecker.cpp:0:0
#<!-- -->15 0x000055e2f0f58aa1 clang::ento::CheckerManager::runCheckersOnASTDecl(clang::Decl const*, clang::ento::AnalysisManager&amp;, clang::ento::BugReporter&amp;) (/home/dyung/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bin/clang-tidy+0x1e9aaa1)
#<!-- -->16 0x000055e2f09623de (anonymous namespace)::AnalysisConsumer::HandleTranslationUnit(clang::ASTContext&amp;) AnalysisConsumer.cpp:0:0
#<!-- -->17 0x000055e2f12a7b20 clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&amp;) (/home/dyung/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bin/clang-tidy+0x21e9b20)
#<!-- -->18 0x000055e2f156c76c clang::ParseAST(clang::Sema&amp;, 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&amp;) (/home/dyung/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bin/clang-tidy+0x211d81e)
#<!-- -->21 0x000055e2f0928b30 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr&lt;clang::CompilerInvocation&gt;, clang::FileManager*, std::shared_ptr&lt;clang::PCHContainerOperations&gt;, clang::DiagnosticConsumer*) (/home/dyung/src/upstream/2c6424e691e32f79bc303203deb1c91634d62286-linux/bi
n/clang-tidy+0x186ab30)
#<!-- -->22 0x000055e2f08c6869 clang::tidy::runClangTidy(clang::tidy::ClangTidyContext&amp;, clang::tooling::CompilationDatabase const&amp;, llvm::ArrayRef&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;&gt;, llvm::IntrusiveRefCntPtr&lt;llvm::vfs::OverlayFileSystem&gt;, bool, bool, llv
m::StringRef)::ActionFactory::runInvocation(std::shared_ptr&lt;clang::CompilerInvocation&gt;, clang::FileManager*, std::shared_ptr&lt;clang::PCHContainerOperations&gt;, clang::DiagnosticConsumer*) ClangTidy.cpp:0:0
#<!-- -->23 0x000055e2f091faa7 clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr&lt;clang::CompilerInvocation&gt;, std::shared_ptr&lt;clang::PCHContainerOperations&gt;) (/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&amp;, clang::tooling::CompilationDatabase const&amp;, llvm::ArrayRef&lt;std::__cxx11::basic_string&lt;char, std::char_traits&lt;char&gt;, std::allocator&lt;char&gt;&gt;&gt;, llvm::IntrusiveRefCntPtr&lt;llvm::vfs::OverlayFileSystem&gt;, 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.

@steakhal
Copy link
Contributor

@rniwa I think this one is yours.
Btw, does it make sense to run these checkeres by default? I have the suspicion that these are domain specific checkers.

@rniwa
Copy link
Contributor

rniwa commented Nov 20, 2024

Oh yeah, these checkers are definitely domain specific.

@rniwa
Copy link
Contributor

rniwa commented Nov 21, 2024

Fixing this debug assertion in #117090.

@steakhal
Copy link
Contributor

Oh yeah, these checkers are definitely domain specific.

Then I think we should review what checkers are enabled by default in clang-tidy, because this and possibly more checkers likely needs to be disabled there. I'll have a look.

@rniwa
Copy link
Contributor

rniwa commented Nov 21, 2024

I think all static analyzers under "WebKit" and "alpha.WebKit" can be disabled by default.

@rniwa
Copy link
Contributor

rniwa commented Nov 21, 2024

Fixed in 9492744

@rniwa rniwa closed this as completed Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:static analyzer crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

5 participants