Skip to content
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

[clang-tidy] SuspiciousCallArgumentCheck "Name is not a simple identifier" assertion #54074

Closed
steakhal opened this issue Feb 25, 2022 · 4 comments
Assignees
Labels
clang-tidy crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@steakhal
Copy link
Contributor

Consider this code:

template <typename a> class b {
public:
  b(a);
};
class c {
public:
  template <int d> c(const char (&)[d]);
};
class C;
int operator-(const C &, const C &);
class e {
public:
  e(int);
  void f(c, b<int(const C &, const C &)>);
};
int g;
void h() { e(g).f("", operator-); }

When executing the clang-tidy -checks=-*,readability-suspicious-call-argument FileCheck2.cpp, it crash with the following trace:

0.      Program arguments: build/release/bin/clang-tidy -checks=-*,readability-suspicious-call-argument FileCheck.cpp
1.      <eof> parser at end of file
 #0 0x00007f986dc6d473 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (build/release/bin/../lib/libLLVMSupport.so.15git+0x218473)
 #1 0x00007f986dc6b22e llvm::sys::RunSignalHandlers() (build/release/bin/../lib/libLLVMSupport.so.15git+0x21622e)
 #2 0x00007f986dc6d93f SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f986fdf7980 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x12980)
 #4 0x00007f986ccdffb7 raise /build/glibc-S9d2JN/glibc-2.27/signal/../sysdeps/unix/sysv/linux/raise.c:51:0
 #5 0x00007f986cce1921 abort /build/glibc-S9d2JN/glibc-2.27/stdlib/abort.c:81:0
 #6 0x00007f986ccd148a __assert_fail_base /build/glibc-S9d2JN/glibc-2.27/assert/assert.c:89:0
 #7 0x00007f986ccd1502 (/lib/x86_64-linux-gnu/libc.so.6+0x30502)
 #8 0x00007f986f1009c1 (build/release/bin/../lib/libclangTidyReadabilityModule.so.15git+0x2289c1)
 #9 0x00007f986f0ffc99 clang::tidy::readability::SuspiciousCallArgumentCheck::check(clang::ast_matchers::MatchFinder::MatchResult const&) (build/release/bin/../lib/libclangTidyReadabilityModule.so.15git+0x227c99)
#10 0x00007f986edcb6c2 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::MatchVisitor::visitMatch(clang::ast_matchers::BoundNodes const&) ASTMatchFinder.cpp:0:0
#11 0x00007f986edfd93c clang::ast_matchers::internal::BoundNodesTreeBuilder::visitMatches(clang::ast_matchers::internal::BoundNodesTreeBuilder::Visitor*) (build/release/bin/../lib/libclangASTMatchers.so.15git+0xac93c)
#12 0x00007f986edcad3a clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchWithFilter(clang::DynTypedNode const&) ASTMatchFinder.cpp:0:0
#13 0x00007f986edcd697 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#14 0x00007f986edd6b9b clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseTranslationUnitDecl(clang::TranslationUnitDecl*) ASTMatchFinder.cpp:0:0
#15 0x00007f986edcde4a clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#16 0x00007f986ed97c61 clang::ast_matchers::MatchFinder::matchAST(clang::ASTContext&) (build/release/bin/../lib/libclangASTMatchers.so.15git+0x46c61)
#17 0x00007f986bb4512c clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) (build/release/bin/../lib/../lib/libclangFrontend.so.15git+0x1f712c)
#18 0x00007f986757d8a4 clang::ParseAST(clang::Sema&, bool, bool) (build/release/bin/../lib/../lib/../lib/libclangParse.so.15git+0x638a4)
#19 0x00007f986bb05810 clang::FrontendAction::Execute() (build/release/bin/../lib/../lib/libclangFrontend.so.15git+0x1b7810)
#20 0x00007f986ba57fff clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (build/release/bin/../lib/../lib/libclangFrontend.so.15git+0x109fff)
#21 0x00007f986ee67c7d clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) (build/release/bin/../lib/libclangTooling.so.15git+0x42c7d)
#22 0x00007f986eea24b6 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
#23 0x00007f986ee679da clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr<clang::CompilerInvocation>, std::shared_ptr<clang::PCHContainerOperations>) (build/release/bin/../lib/libclangTooling.so.15git+0x429da)
#24 0x00007f986ee667d3 clang::tooling::ToolInvocation::run() (build/release/bin/../lib/libclangTooling.so.15git+0x417d3)
#25 0x00007f986ee694ee clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (build/release/bin/../lib/libclangTooling.so.15git+0x444ee)
#26 0x00007f986ee9ce4a 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) (build/release/bin/../lib/libclangTidy.so.15git+0x28e4a)
#27 0x00007f987020806d clang::tidy::clangTidyMain(int, char const**) (build/release/bin/../lib/libclangTidyMain.so.15git+0xb06d)
#28 0x00007f986ccc2bf7 __libc_start_main /build/glibc-S9d2JN/glibc-2.27/csu/../csu/libc-start.c:344:0
#29 0x0000000000201c2a _start (build/release/bin/clang-tidy+0x201c2a)

I'm using the commit 2f90668, Wed Feb 23 17:00:04 2022 +0100.

@steakhal steakhal added clang-tidy crash Prefer [crash-on-valid] or [crash-on-invalid] labels Feb 25, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 25, 2022

@llvm/issue-subscribers-clang-tidy

@whisperity
Copy link
Member

Confirmed. I was able to hand-craft a less convoluted example that produces the same crash:

class T {};
using OperatorTy = int(const T&, const T&);
int operator-(const T&, const T&);

template <typename U>
struct Wrap {
  Wrap(U);
};

template <typename V>
void wrapTaker(V, Wrap<OperatorTy>);

void crash() {
  wrapTaker(0, operator-);
}

I'll fix it ASAP, yeah the problem is definitely lies in trying to "name" the function with a nontrivial identifier...

@whisperity
Copy link
Member

Fix available for review in D120555.

@whisperity
Copy link
Member

Fixed in 416e689.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-tidy crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

3 participants