-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Description
When running clang-tidy
with the check llvmlibc-callee-namespace
enabled I run into an assertion with the following code snippet:
#include <gtest/gtest.h>
struct A
{
int operator() (int) const;
};
template<typename>
struct MyTest : public testing::Test {};
TYPED_TEST_SUITE_P(MyTest);
TYPED_TEST_P(MyTest, my)
{
EXPECT_TRUE(A()(0));
}
REGISTER_TYPED_TEST_SUITE_P(MyTest, my);
INSTANTIATE_TYPED_TEST_SUITE_P(MYTEST, MyTest, testing::Types<int>);
Assertion:
clang-tidy: /tmp/LLVM/llvm-project/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp:178: clang::DiagnosticBuilder clang::tidy::ClangTidyContext::diag(llvm::StringRef, clang::SourceLocation, llvm::StringRef, clang::DiagnosticIDs::Level): Assertion `Loc.isValid()' failed.
Apparently, the reason for the crash is that clang-tidy creates invalid source locations (the assertion Loc.isValid()
fails and the stack trace shows <invalid sloc>
). Unfortunately, this is not visible if I put everything into a single file.
Therefore, the test case is not completely self-contained. It requires googletest version 1.14.0 to be installed
which can be downloaded from GitHub. It just needs to be unpacked but not built.
For easier usage I'm adding a tar archive with all the needed bits, just unpack it and run
clang-tidy -checks=-*,llvmlibc-callee-namespace CTbug.cc -- -I googletest-1.14.0/googletest/include
inside the 'BUG' directory: BUG.tar.gz
Stack dump:
0. Program arguments: /LLVM/LLVM-trunk/bin/clang-tidy -checks=-*,llvmlibc-callee-namespace CTbug.cc -- -I googletest-1.14.0/googletest/include
1. <eof> parser at end of file
2. ASTMatcher: Processing 'llvmlibc-callee-namespace' against:
DeclRefExpr : <<invalid sloc>, BUG/CTbug.cc:15:3 <Spelling=col:20>>
--- Bound Nodes Begin ---
func - { CXXMethodDecl A::operator() : <BUG/CTbug.cc:5:3, col:24> }
use-site - { DeclRefExpr : <<invalid sloc>, BUG/CTbug.cc:15:3 <Spelling=col:20>> }
--- Bound Nodes End ---
#0 0x00000000045778e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/LLVM/LLVM-trunk/bin/clang-tidy+0x45778e8)
#1 0x000000000457500c SignalHandler(int) Signals.cpp:0:0
#2 0x00007fc8d5890ce0 __restore_rt (/lib64/libpthread.so.0+0x12ce0)
#3 0x00007fc8d430fa9f raise (/lib64/libc.so.6+0x4ea9f)
#4 0x00007fc8d42e2e05 abort (/lib64/libc.so.6+0x21e05)
#5 0x00007fc8d42e2cd9 _nl_load_domain.cold.0 (/lib64/libc.so.6+0x21cd9)
#6 0x00007fc8d43083f6 (/lib64/libc.so.6+0x473f6)
#7 0x0000000001804686 clang::tidy::ClangTidyContext::diag(llvm::StringRef, clang::SourceLocation, llvm::StringRef, clang::DiagnosticIDs::Level) (/LLVM/LLVM-trunk/bin/clang-tidy+0x1804686)
#8 0x00000000017fc3be clang::tidy::ClangTidyCheck::diag(clang::SourceLocation, llvm::StringRef, clang::DiagnosticIDs::Level) (/LLVM/LLVM-trunk/bin/clang-tidy+0x17fc3be)
#9 0x0000000000dd4e92 clang::tidy::llvm_libc::CalleeNamespaceCheck::check(clang::ast_matchers::MatchFinder::MatchResult const&) (/LLVM/LLVM-trunk/bin/clang-tidy+0xdd4e92)
#10 0x0000000003196219 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::MatchVisitor::visitMatch(clang::ast_matchers::BoundNodes const&) ASTMatchFinder.cpp:0:0
#11 0x00000000031db647 clang::ast_matchers::internal::BoundNodesTreeBuilder::visitMatches(clang::ast_matchers::internal::BoundNodesTreeBuilder::Visitor*) (/LLVM/LLVM-trunk/bin/clang-tidy+0x31db647)
#12 0x000000000319874c clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchWithFilter(clang::DynTypedNode const&) ASTMatchFinder.cpp:0:0
#13 0x00000000031c0561 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*>>>>*) ASTMatchFinder.cpp:0:0
#14 0x00000000031c304e clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseImplicitCastExpr(clang::ImplicitCastExpr*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*>>>>*) ASTMatchFinder.cpp:0:0
#15 0x00000000031bf0b9 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::dataTraverseNode(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*>>>>*) ASTMatchFinder.cpp:0:0
#16 0x00000000031c03e0 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*>>>>*) ASTMatchFinder.cpp:0:0
#17 0x00000000031c67a9 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*>>>>*) (.constprop.9939) ASTMatchFinder.cpp:0:0
#18 0x00000000031cfb35 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseVarDecl(clang::VarDecl*) ASTMatchFinder.cpp:0:0
#19 0x00000000031bb1cb clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#20 0x00000000031bbd09 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#21 0x00000000031bde8b clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::dataTraverseNode(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*>>>>*) ASTMatchFinder.cpp:0:0
#22 0x00000000031c03e0 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*>>>>*) ASTMatchFinder.cpp:0:0
#23 0x00000000031c67a9 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseStmt(clang::Stmt*, llvm::SmallVectorImpl<llvm::PointerIntPair<clang::Stmt*, 1u, bool, llvm::PointerLikeTypeTraits<clang::Stmt*>, llvm::PointerIntPairInfo<clang::Stmt*, 1u, llvm::PointerLikeTypeTraits<clang::Stmt*>>>>*) (.constprop.9939) ASTMatchFinder.cpp:0:0
#24 0x00000000031d0469 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseFunctionHelper(clang::FunctionDecl*) ASTMatchFinder.cpp:0:0
#25 0x00000000031d0635 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseCXXMethodDecl(clang::CXXMethodDecl*) ASTMatchFinder.cpp:0:0
#26 0x00000000031bb21c clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#27 0x00000000031bbd09 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#28 0x00000000031bc74a clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDeclContextHelper(clang::DeclContext*) (.part.9771) ASTMatchFinder.cpp:0:0
#29 0x00000000031bb39f clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#30 0x00000000031bbd09 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#31 0x00000000031bce83 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseTemplateInstantiations(clang::ClassTemplateDecl*) ASTMatchFinder.cpp:0:0
#32 0x00000000031bba08 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#33 0x00000000031bbd09 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#34 0x00000000031bc74a clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDeclContextHelper(clang::DeclContext*) (.part.9771) ASTMatchFinder.cpp:0:0
#35 0x00000000031ce1ce clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseNamespaceDecl(clang::NamespaceDecl*) ASTMatchFinder.cpp:0:0
#36 0x00000000031bb62f clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#37 0x00000000031bbd09 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#38 0x00000000031bc74a clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDeclContextHelper(clang::DeclContext*) (.part.9771) ASTMatchFinder.cpp:0:0
#39 0x00000000031cef05 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseTranslationUnitDecl(clang::TranslationUnitDecl*) ASTMatchFinder.cpp:0:0
#40 0x00000000031bb733 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#41 0x00000000031bbd09 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#42 0x00000000031bc001 clang::ast_matchers::MatchFinder::matchAST(clang::ASTContext&) (/LLVM/LLVM-trunk/bin/clang-tidy+0x31bc001)
#43 0x00000000020478b8 clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) (/LLVM/LLVM-trunk/bin/clang-tidy+0x20478b8)
#44 0x000000000229e37c clang::ParseAST(clang::Sema&, bool, bool) (/LLVM/LLVM-trunk/bin/clang-tidy+0x229e37c)
#45 0x0000000002011b69 clang::FrontendAction::Execute() (/LLVM/LLVM-trunk/bin/clang-tidy+0x2011b69)
#46 0x0000000001f9a909 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/LLVM/LLVM-trunk/bin/clang-tidy+0x1f9a909)
#47 0x0000000001841409 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) (/LLVM/LLVM-trunk/bin/clang-tidy+0x1841409)
#48 0x00000000017ef28e 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
#49 0x000000000183c1ab clang::tooling::ToolInvocation::run() (/LLVM/LLVM-trunk/bin/clang-tidy+0x183c1ab)
#50 0x000000000183ecbd clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (/LLVM/LLVM-trunk/bin/clang-tidy+0x183ecbd)
#51 0x00000000017fb3f9 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) (/LLVM/LLVM-trunk/bin/clang-tidy+0x17fb3f9)
#52 0x0000000000ab3cc2 clang::tidy::clangTidyMain(int, char const**) (/LLVM/LLVM-trunk/bin/clang-tidy+0xab3cc2)
#53 0x00007fc8d42fbcf3 __libc_start_main (/lib64/libc.so.6+0x3acf3)
#54 0x0000000000aa998e _start (/LLVM/LLVM-trunk/bin/clang-tidy+0xaa998e)