Skip to content

Commit

Permalink
[clang-tidy] Clarify bugprone-branch-clone diagnostic message
Browse files Browse the repository at this point in the history
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
  • Loading branch information
NagyDonat committed Feb 17, 2023
1 parent df82394 commit 2b51c8c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
Expand Up @@ -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());
Expand Down
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Expand Up @@ -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)
}
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2b51c8c

Please sign in to comment.