Author: Donát Nagy Date: 2023-02-17T17:05:19+01:00 New Revision: 2b51c8cd2ac6b9a6a5b713700c8299954980242d
URL: https://github.com/llvm/llvm-project/commit/2b51c8cd2ac6b9a6a5b713700c8299954980242d DIFF: https://github.com/llvm/llvm-project/commit/2b51c8cd2ac6b9a6a5b713700c8299954980242d.diff LOG: [clang-tidy] Clarify bugprone-branch-clone diagnostic message This simple commit inserts "body" into the message "repeated branch _body_ in conditional chain". This is motivated by feedback from a user who (at first glance) thought that clang-tidy complained about a repeated branch _condition_. Differential Revision: https://reviews.llvm.org/D143917 Added: Modified: clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-if-constexpr-template.cpp clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp Removed: ################################################################################ diff --git a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp index 41b8d32500cdb..df232e9a64cd0 100644 --- a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp @@ -141,7 +141,7 @@ void BranchCloneCheck::check(const MatchFinder::MatchResult &Result) { if (NumCopies == 2) { // We report the first occurrence only when we find the second one. diag(Branches[I]->getBeginLoc(), - "repeated branch in conditional chain"); + "repeated branch body in conditional chain"); SourceLocation End = Lexer::getLocForEndOfToken(Branches[I]->getEndLoc(), 0, *Result.SourceManager, getLangOpts()); diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-if-constexpr-template.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-if-constexpr-template.cpp index 382330139c8c5..10cf06e8d9cc8 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-if-constexpr-template.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-if-constexpr-template.cpp @@ -5,7 +5,7 @@ void handle(int); template <unsigned Index> void shouldFail() { if constexpr (Index == 0) { - // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: repeated branch in conditional chain [bugprone-branch-clone] + // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: repeated branch body in conditional chain [bugprone-branch-clone] handle(0); } else if constexpr (Index == 1) { handle(1); @@ -28,7 +28,7 @@ void shouldPass() { void shouldFailNonTemplate() { constexpr unsigned Index = 1; if constexpr (Index == 0) { - // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: repeated branch in conditional chain [bugprone-branch-clone] + // CHECK-MESSAGES: :[[@LINE-1]]:29: warning: repeated branch body in conditional chain [bugprone-branch-clone] handle(0); } else if constexpr (Index == 1) { handle(1); diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c index a51069828b3eb..a4cb7347f88c6 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c @@ -9,6 +9,6 @@ int y = 1; d = b; void f(void) { - // CHECK-MESSAGES: warning: repeated branch in conditional chain [bugprone-branch-clone] + // CHECK-MESSAGES: warning: repeated branch body in conditional chain [bugprone-branch-clone] a(x, y) } diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp index 09f87cedfceb6..1525ba2802d16 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp @@ -388,7 +388,7 @@ void test_macro13(int in, int &out) { void test_chain1(int in, int &out) { if (in > 77) -// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch in conditional chain [bugprone-branch-clone] +// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch body in conditional chain [bugprone-branch-clone] out++; // CHECK-MESSAGES: :[[@LINE-1]]:10: note: end of the original else if (in > 55) @@ -400,7 +400,7 @@ void test_chain1(int in, int &out) { void test_chain2(int in, int &out) { if (in > 77) -// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch in conditional chain [bugprone-branch-clone] +// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch body in conditional chain [bugprone-branch-clone] out++; // CHECK-MESSAGES: :[[@LINE-1]]:10: note: end of the original else if (in > 55) @@ -422,7 +422,7 @@ void test_chain2(int in, int &out) { void test_chain3(int in, int &out) { if (in > 77) { -// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch in conditional chain [bugprone-branch-clone] +// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch body in conditional chain [bugprone-branch-clone] out++; out++; // CHECK-MESSAGES: :[[@LINE+1]]:4: note: end of the original @@ -452,7 +452,7 @@ void test_chain3(int in, int &out) { // describes all branches of the first one before mentioning the second one. void test_chain4(int in, int &out) { if (in > 77) { -// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch in conditional chain [bugprone-branch-clone] +// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch body in conditional chain [bugprone-branch-clone] out++; out++; // CHECK-MESSAGES: :[[@LINE+1]]:4: note: end of the original @@ -463,7 +463,7 @@ void test_chain4(int in, int &out) { out++; out++; } else if (in > 42) -// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch in conditional chain [bugprone-branch-clone] +// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch body in conditional chain [bugprone-branch-clone] out--; // CHECK-MESSAGES: :[[@LINE-1]]:10: note: end of the original else if (in > 28) { @@ -485,7 +485,7 @@ void test_chain4(int in, int &out) { void test_chain5(int in, int &out) { if (in > 77) -// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch in conditional chain [bugprone-branch-clone] +// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch body in conditional chain [bugprone-branch-clone] out++; // CHECK-MESSAGES: :[[@LINE-1]]:10: note: end of the original else if (in > 55) @@ -507,7 +507,7 @@ void test_chain5(int in, int &out) { void test_chain6(int in, int &out) { if (in > 77) { -// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch in conditional chain [bugprone-branch-clone] +// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch body in conditional chain [bugprone-branch-clone] out++; out++; // CHECK-MESSAGES: :[[@LINE+1]]:4: note: end of the original @@ -538,7 +538,7 @@ void test_nested(int a, int b, int c, int &out) { // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: if with identical then and else branches [bugprone-branch-clone] // CHECK-MESSAGES: :[[@LINE+27]]:5: note: else branch starts here if (b > 5) { -// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch in conditional chain [bugprone-branch-clone] +// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch body in conditional chain [bugprone-branch-clone] // CHECK-MESSAGES: :[[@LINE+9]]:6: note: end of the original // CHECK-MESSAGES: :[[@LINE+8]]:24: note: clone 1 starts here // CHECK-MESSAGES: :[[@LINE+14]]:12: note: clone 2 starts here @@ -565,7 +565,7 @@ void test_nested(int a, int b, int c, int &out) { } } else { if (b > 5) { -// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch in conditional chain [bugprone-branch-clone] +// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch body in conditional chain [bugprone-branch-clone] // CHECK-MESSAGES: :[[@LINE+9]]:6: note: end of the original // CHECK-MESSAGES: :[[@LINE+8]]:24: note: clone 1 starts here // CHECK-MESSAGES: :[[@LINE+14]]:12: note: clone 2 starts here @@ -948,7 +948,7 @@ char no_real_body(int in, int &out) { return 'A'; if (in > 77) -// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch in conditional chain [bugprone-branch-clone] +// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch body in conditional chain [bugprone-branch-clone] out++; // CHECK-MESSAGES: :[[@LINE-1]]:10: note: end of the original else if (in > 55) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits