[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
This commit is contained in:
Donát Nagy 2023-02-13 15:35:24 +01:00 committed by Donát Nagy
parent df82394e7a
commit 2b51c8cd2a
4 changed files with 14 additions and 14 deletions

View File

@ -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());

View File

@ -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);

View File

@ -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)
}

View File

@ -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)