[clang-tools-extra] [llvm] [clang] Add clang-tidy check to suggest replacement of conditional statement with std::min/std::max (PR #77816)
FĂ©lix-Antoine Constantin via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 22 14:53:44 PST 2024
felix642 wrote:
@11happy I've compiled your code to test it on llvm's project and clang-tidy seems to sometimes crash. Would you be able to have a look before we merge this PR ?
```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /home/felix/git/llvm-project/build/bin/clang-tidy -checks=-*,readability-use-std-* -export-fixes /tmp/tmpswi2gkux/tmpbofvt76t.yaml -p=build /home/felix/git/llvm-project/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp
1. <eof> parser at end of file
2. ASTMatcher: Processing 'readability-use-std-min-max' against:
IfStmt : </home/felix/git/llvm-project/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp:2930:5, line:2931:17>
--- Bound Nodes Begin ---
AssignLhs - { DeclRefExpr : </home/felix/git/llvm-project/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp:2931:7> }
AssignRhs - { CXXBoolLiteralExpr : </home/felix/git/llvm-project/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp:2931:17> }
CondLhs - { CXXMemberCallExpr : </home/felix/git/llvm-project/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp:2930:9, col:29> }
CondRhs - { IntegerLiteral : </home/felix/git/llvm-project/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp:2930:33> }
if - { IfStmt : </home/felix/git/llvm-project/llvm/lib/Target/NVPTX/NVPTXISelLowering.cpp:2930:5, line:2931:17> }
--- Bound Nodes End ---
#0 0x0000000004208bab llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/felix/git/llvm-project/build/bin/clang-tidy+0x4208bab)
#1 0x00000000042062bb SignalHandler(int) Signals.cpp:0:0
#2 0x00007f0a8f4e7420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
#3 0x000000000112e7e9 clang::tidy::readability::UseStdMinMaxCheck::check(clang::ast_matchers::MatchFinder::MatchResult const&) (/home/felix/git/llvm-project/build/bin/clang-tidy+0x112e7e9)
#4 0x0000000002f5ef43 clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::MatchVisitor::visitMatch(clang::ast_matchers::BoundNodes const&) ASTMatchFinder.cpp:0:0
#5 0x0000000002f89f21 clang::ast_matchers::internal::BoundNodesTreeBuilder::visitMatches(clang::ast_matchers::internal::BoundNodesTreeBuilder::Visitor*) (/home/felix/git/llvm-project/build/bin/clang-tidy+0x2f89f21)
#6 0x0000000002f60b6e clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor::matchWithFilter(clang::DynTypedNode const&) ASTMatchFinder.cpp:0:0
#7 0x0000000002f84b10 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseMSPropertySubscriptExpr(clang::MSPropertySubscriptExpr*, 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 0x0000000002f7aaf8 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 0x0000000002f7ad0b 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 0x0000000002f7ec42 clang::RecursiveASTVisitor<clang::ast_matchers::internal::(anonymous namespace)::MatchASTVisitor>::TraverseFunctionHelper(clang::FunctionDecl*) ASTMatchFinder.cpp:0:0
```
This is the bit of code that your check doesn't seems to like :
```
bool NeedExt = false;
if(EltVT.getSizeInBits() < 16)
NeedExt = true;
```
https://github.com/llvm/llvm-project/pull/77816
More information about the cfe-commits
mailing list