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

Crash in modernize-use-ranges check #100406

Closed
matthew-f opened this issue Jul 24, 2024 · 9 comments · Fixed by #100427
Closed

Crash in modernize-use-ranges check #100406

matthew-f opened this issue Jul 24, 2024 · 9 comments · Fixed by #100427
Assignees
Labels
clang-tidy crash Prefer [crash-on-valid] or [crash-on-invalid] release:backport

Comments

@matthew-f
Copy link
Contributor

matthew-f commented Jul 24, 2024

The modernize-use-ranges check is crashing. This is the backtrace:

1.	<eof> parser at end of file
2.	ASTMatcher: Processing 'modernize-use-ranges' against:
	CallExpr : </home/xxx/xxx/source/trunk/500_tmp/enterprise/cloud/servers/user/logins.cpp:241:4, line:243:31>
--- Bound Nodes Begin ---
    ArgName0 - { DeclRefExpr : </home/xxx/xxx/source/trunk/500_tmp/enterprise/cloud/servers/user/logins.cpp:241:16> }
    CallExpr0:2:0 - { CallExpr : </home/xxx/xxx/source/trunk/500_tmp/enterprise/cloud/servers/user/logins.cpp:241:4, line:243:31> }
    FuncDecl - { FunctionDecl std::_V2::rotate : </usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_algo.h:1403:5 <Spelling=/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/x86_64-linux-gnu/c++/11/bits/c++config.h:169:32>, /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_algo.h:1416:5> }
--- Bound Nodes End ---
 #0 0x000059a2eef79530 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/local/llvm-20240723/bin/clang-tidy+0x48f6530)
 #1 0x000059a2eef76b0e SignalHandler(int) Signals.cpp:0:0
 #2 0x0000768f8a242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x000059a2ebfb09bc clang::tidy::utils::UseRangesCheck::check(clang::ast_matchers::MatchFinder::MatchResult const&) (/usr/local/llvm-20240723/bin/clang-tidy+0x192d9bc)
 #4 0x000059a2edab7e36 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::MatchVisitor::visitMatch(clang::ast_matchers::BoundNodes const&) ASTMatchFinder.cpp:0:0
 #5 0x000059a2edae5b8f clang::ast_matchers::internal::BoundNodesTreeBuilder::visitMatches(clang::ast_matchers::internal::BoundNodesTreeBuilder::Visitor*) (/usr/local/llvm-20240723/bin/clang-tidy+0x3462b8f)
 #6 0x000059a2edab8a30 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchWithFilter(clang::DynTypedNode const&) ASTMatchFinder.cpp:0:0
 #7 0x000059a2edadd4d0 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseObjCAvailabilityCheckExpr(clang::ObjCAvailabilityCheckExpr*, 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
 #8 0x000059a2edad5950 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
 #9 0x000059a2edad5adb 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.0) ASTMatchFinder.cpp:0:0
#10 0x000059a2edadf90f clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseFunctionHelper(clang::FunctionDecl*) ASTMatchFinder.cpp:0:0
#11 0x000059a2edadfb83 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseCXXMethodDecl(clang::CXXMethodDecl*) ASTMatchFinder.cpp:0:0
#12 0x000059a2edad02cf clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#13 0x000059a2edad03d9 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDeclContextHelper(clang::DeclContext*) (.part.0) ASTMatchFinder.cpp:0:0
#14 0x000059a2edadbad8 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseTranslationUnitDecl(clang::TranslationUnitDecl*) ASTMatchFinder.cpp:0:0
#15 0x000059a2edad02cf clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0
#16 0x000059a2edad0605 clang::ast_matchers::MatchFinder::matchAST(clang::ASTContext&) (/usr/local/llvm-20240723/bin/clang-tidy+0x344d605)
#17 0x000059a2ec84a900 clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) (/usr/local/llvm-20240723/bin/clang-tidy+0x21c7900)
#18 0x000059a2ecad633c clang::ParseAST(clang::Sema&, bool, bool) (/usr/local/llvm-20240723/bin/clang-tidy+0x245333c)
#19 0x000059a2ec80a449 clang::FrontendAction::Execute() (/usr/local/llvm-20240723/bin/clang-tidy+0x2187449)
#20 0x000059a2ec777c39 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/local/llvm-20240723/bin/clang-tidy+0x20f4c39)
#21 0x000059a2ec01ca04 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) (/usr/local/llvm-20240723/bin/clang-tidy+0x1999a04)
#22 0x000059a2ebfbe9fe 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 0x000059a2ec016035 clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr<clang::CompilerInvocation>, std::shared_ptr<clang::PCHContainerOperations>) (/usr/local/llvm-20240723/bin/clang-tidy+0x1993035)
#24 0x000059a2ec0185db clang::tooling::ToolInvocation::run() (/usr/local/llvm-20240723/bin/clang-tidy+0x19955db)
#25 0x000059a2ec01a78f clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (/usr/local/llvm-20240723/bin/clang-tidy+0x199778f)
#26 0x000059a2ebfc7dea 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) (/usr/local/llvm-20240723/bin/clang-tidy+0x1944dea)
#27 0x000059a2eb23425a clang::tidy::clangTidyMain(int, char const**) (/usr/local/llvm-20240723/bin/clang-tidy+0xbb125a)
#28 0x0000768f8a229d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#29 0x0000768f8a229e40 call_init ./csu/../csu/libc-start.c:128:20
#30 0x0000768f8a229e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#31 0x000059a2eb22a4d5 _start (/usr/local/llvm-20240723/bin/clang-tidy+0xba74d5)
Segmentation fault (core dumped)

The problem is the 'Qualified name is not found in 'Replaces'. As a hack, this fixes it:

auto Iter = Replaces.find(Qualified);

if (Iter == Replaces.end()) {
  return;
}

In the instance when it crashed, the 'Qualified' name was ::std::_V2::rotate. The 'Replaces' map does contain '::std::rotate'

I don't know this code at all, and from the assert it looks like this is not expected, so I'm afraid I'm not submitting a proper fix.

@EugeneZelenko EugeneZelenko added clang-tidy crash Prefer [crash-on-valid] or [crash-on-invalid] and removed new issue labels Jul 24, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 24, 2024

@llvm/issue-subscribers-clang-tidy

Author: None (matthew-f)

The modernize-use-ranges check is crashing. This is the backtrace: ``` 1. <eof> parser at end of file 2. ASTMatcher: Processing 'modernize-use-ranges' against: CallExpr : </home/xxx/xxx/source/trunk/500_tmp/enterprise/cloud/servers/user/logins.cpp:241:4, line:243:31> --- Bound Nodes Begin --- ArgName0 - { DeclRefExpr : </home/xxx/xxx/source/trunk/500_tmp/enterprise/cloud/servers/user/logins.cpp:241:16> } CallExpr0:2:0 - { CallExpr : </home/xxx/xxx/source/trunk/500_tmp/enterprise/cloud/servers/user/logins.cpp:241:4, line:243:31> } FuncDecl - { FunctionDecl std::_V2::rotate : </usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_algo.h:1403:5 <Spelling=/usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/x86_64-linux-gnu/c++/11/bits/c++config.h:169:32>, /usr/lib/gcc/x86_64-linux-gnu/11/../../../../include/c++/11/bits/stl_algo.h:1416:5> } --- Bound Nodes End --- #0 0x000059a2eef79530 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/local/llvm-20240723/bin/clang-tidy+0x48f6530) #1 0x000059a2eef76b0e SignalHandler(int) Signals.cpp:0:0 #2 0x0000768f8a242520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520) #3 0x000059a2ebfb09bc clang::tidy::utils::UseRangesCheck::check(clang::ast_matchers::MatchFinder::MatchResult const&) (/usr/local/llvm-20240723/bin/clang-tidy+0x192d9bc) #4 0x000059a2edab7e36 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::MatchVisitor::visitMatch(clang::ast_matchers::BoundNodes const&) ASTMatchFinder.cpp:0:0 #5 0x000059a2edae5b8f clang::ast_matchers::internal::BoundNodesTreeBuilder::visitMatches(clang::ast_matchers::internal::BoundNodesTreeBuilder::Visitor*) (/usr/local/llvm-20240723/bin/clang-tidy+0x3462b8f) #6 0x000059a2edab8a30 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchWithFilter(clang::DynTypedNode const&) ASTMatchFinder.cpp:0:0 #7 0x000059a2edadd4d0 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseObjCAvailabilityCheckExpr(clang::ObjCAvailabilityCheckExpr*, 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 #8 0x000059a2edad5950 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 #9 0x000059a2edad5adb 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.0) ASTMatchFinder.cpp:0:0 #10 0x000059a2edadf90f clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseFunctionHelper(clang::FunctionDecl*) ASTMatchFinder.cpp:0:0 #11 0x000059a2edadfb83 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseCXXMethodDecl(clang::CXXMethodDecl*) ASTMatchFinder.cpp:0:0 #12 0x000059a2edad02cf clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0 #13 0x000059a2edad03d9 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseDeclContextHelper(clang::DeclContext*) (.part.0) ASTMatchFinder.cpp:0:0 #14 0x000059a2edadbad8 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseTranslationUnitDecl(clang::TranslationUnitDecl*) ASTMatchFinder.cpp:0:0 #15 0x000059a2edad02cf clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::TraverseDecl(clang::Decl*) ASTMatchFinder.cpp:0:0 #16 0x000059a2edad0605 clang::ast_matchers::MatchFinder::matchAST(clang::ASTContext&) (/usr/local/llvm-20240723/bin/clang-tidy+0x344d605) #17 0x000059a2ec84a900 clang::MultiplexConsumer::HandleTranslationUnit(clang::ASTContext&) (/usr/local/llvm-20240723/bin/clang-tidy+0x21c7900) #18 0x000059a2ecad633c clang::ParseAST(clang::Sema&, bool, bool) (/usr/local/llvm-20240723/bin/clang-tidy+0x245333c) #19 0x000059a2ec80a449 clang::FrontendAction::Execute() (/usr/local/llvm-20240723/bin/clang-tidy+0x2187449) #20 0x000059a2ec777c39 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/local/llvm-20240723/bin/clang-tidy+0x20f4c39) #21 0x000059a2ec01ca04 clang::tooling::FrontendActionFactory::runInvocation(std::shared_ptr<clang::CompilerInvocation>, clang::FileManager*, std::shared_ptr<clang::PCHContainerOperations>, clang::DiagnosticConsumer*) (/usr/local/llvm-20240723/bin/clang-tidy+0x1999a04) #22 0x000059a2ebfbe9fe 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 0x000059a2ec016035 clang::tooling::ToolInvocation::runInvocation(char const*, clang::driver::Compilation*, std::shared_ptr<clang::CompilerInvocation>, std::shared_ptr<clang::PCHContainerOperations>) (/usr/local/llvm-20240723/bin/clang-tidy+0x1993035) #24 0x000059a2ec0185db clang::tooling::ToolInvocation::run() (/usr/local/llvm-20240723/bin/clang-tidy+0x19955db) #25 0x000059a2ec01a78f clang::tooling::ClangTool::run(clang::tooling::ToolAction*) (/usr/local/llvm-20240723/bin/clang-tidy+0x199778f) #26 0x000059a2ebfc7dea 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) (/usr/local/llvm-20240723/bin/clang-tidy+0x1944dea) #27 0x000059a2eb23425a clang::tidy::clangTidyMain(int, char const**) (/usr/local/llvm-20240723/bin/clang-tidy+0xbb125a) #28 0x0000768f8a229d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16 #29 0x0000768f8a229e40 call_init ./csu/../csu/libc-start.c:128:20 #30 0x0000768f8a229e40 __libc_start_main ./csu/../csu/libc-start.c:379:5 #31 0x000059a2eb22a4d5 _start (/usr/local/llvm-20240723/bin/clang-tidy+0xba74d5) Segmentation fault (core dumped) ```

The problem is the 'Qualified name is not found in 'Replaces'. As a hack, this fixes it:

auto Iter = Replaces.find(Qualified);

if (Iter == Replaces.end()) {
  return;
}

In the instance when it crashed, the 'Qualified' name was ::std::_V2::rotate. The 'Replaces' map does contain '::std::rotate'

I don't know this code at all, and from the assert it looks like this is not expected, so I'm afraid I'm not submitting a proper fix.

@njames93 njames93 self-assigned this Jul 24, 2024
@njames93
Copy link
Member

Sounds like the issue is its not properly handling inline namespaces

@njames93
Copy link
Member

@matthew-f If you wouldn't mind could you test that linked MR. I wasn't able to reproduce the crash with the test cases, but it seems like it should be fixed

@matthew-f
Copy link
Contributor Author

Hi @njames93 . That fix does work on my test case. Thank you.

PiotrZSL pushed a commit that referenced this issue Jul 25, 2024
Crash seems to be caused by the check function not handling inline
namespaces correctly for some instances. Changed how the Replacer is got
from the MatchResult now which should alleviate any potential issues

Fixes #100406
yuxuanchen1997 pushed a commit that referenced this issue Jul 25, 2024
Summary:
Crash seems to be caused by the check function not handling inline
namespaces correctly for some instances. Changed how the Replacer is got
from the MatchResult now which should alleviate any potential issues

Fixes #100406

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60250581
@njames93 njames93 added this to the LLVM 19.X Release milestone Jul 26, 2024
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Jul 26, 2024
@njames93 njames93 reopened this Jul 26, 2024
@tru tru moved this from Needs Triage to Needs Pull Request in LLVM Release Status Jul 26, 2024
@tru
Copy link
Collaborator

tru commented Aug 1, 2024

Should this still be backported to 19? in that case someone needs to request a PR.

@PiotrZSL
Copy link
Member

PiotrZSL commented Aug 1, 2024

Yes, it need.

@njames93
Copy link
Member

njames93 commented Aug 1, 2024

Should this still be backported to 19? in that case someone needs to request a PR.

Can the fix from the linked PR not simply be cherry picked?

@tru
Copy link
Collaborator

tru commented Aug 1, 2024

In order for the release managers to keep up with the number of fixes that should be merged we want people to follow these instructions - https://llvm.org/docs/GitHub.html#backporting-fixes-to-the-release-branches

llvmbot pushed a commit to llvmbot/llvm-project that referenced this issue Aug 1, 2024
Crash seems to be caused by the check function not handling inline
namespaces correctly for some instances. Changed how the Replacer is got
from the MatchResult now which should alleviate any potential issues

Fixes llvm#100406

(cherry picked from commit 0762db6)
@llvmbot llvmbot closed this as completed Aug 1, 2024
@github-project-automation github-project-automation bot moved this from Needs Pull Request to Done in LLVM Release Status Aug 1, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 1, 2024

/pull-request #101482

tru pushed a commit to llvmbot/llvm-project that referenced this issue Aug 5, 2024
Crash seems to be caused by the check function not handling inline
namespaces correctly for some instances. Changed how the Replacer is got
from the MatchResult now which should alleviate any potential issues

Fixes llvm#100406

(cherry picked from commit 0762db6)
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] release:backport
Projects
Development

Successfully merging a pull request may close this issue.

6 participants