[clang-tools-extra] c6d195b - clang-tidy altera-id-dependent-backward-branch: print notes after warning
Carlos Galvez via cfe-commits
cfe-commits at lists.llvm.org
Sun Mar 5 08:07:04 PST 2023
Author: Egor Suvorov
Date: 2023-03-05T16:06:55Z
New Revision: c6d195b366c8256184ff40c5e46339eed96b4a81
URL: https://github.com/llvm/llvm-project/commit/c6d195b366c8256184ff40c5e46339eed96b4a81
DIFF: https://github.com/llvm/llvm-project/commit/c6d195b366c8256184ff40c5e46339eed96b4a81.diff
LOG: clang-tidy altera-id-dependent-backward-branch: print notes after warning
In Clang notes are typically printed after a corresponding warning, not before.
For example, all notes issued before the first warning are ignored.
Running `clang-tidy --checks=-*,altera-id-dependent-backward-branch a.cpp` on the following code:
```
long get_local_id(int);
void error() {
int ThreadID = get_local_id(0);
for (int i = 0; i < ThreadID; i++) {
}
for (int i = 0; i < ThreadID; i++) {
}
}
```
results in two warnings and a single note in between.
Reviewed By: carlosgalvezp
Differential Revision: https://reviews.llvm.org/D145303
Added:
Modified:
clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp b/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
index 66e6d97f500ce..f9225f6ba7f47 100644
--- a/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
+++ b/clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
@@ -241,18 +241,17 @@ void IdDependentBackwardBranchCheck::check(
IdDependencyRecord *IdDepVar = hasIdDepVar(CondExpr);
IdDependencyRecord *IdDepField = hasIdDepField(CondExpr);
if (IdDepVar) {
- // Change one of these to a Note
- diag(IdDepVar->Location, IdDepVar->Message, DiagnosticIDs::Note);
diag(CondExpr->getBeginLoc(),
"backward branch (%select{do|while|for}0 loop) is ID-dependent due "
"to variable reference to %1 and may cause performance degradation")
<< Type << IdDepVar->VariableDeclaration;
+ diag(IdDepVar->Location, IdDepVar->Message, DiagnosticIDs::Note);
} else if (IdDepField) {
- diag(IdDepField->Location, IdDepField->Message, DiagnosticIDs::Note);
diag(CondExpr->getBeginLoc(),
"backward branch (%select{do|while|for}0 loop) is ID-dependent due "
"to member reference to %1 and may cause performance degradation")
<< Type << IdDepField->FieldDeclaration;
+ diag(IdDepField->Location, IdDepField->Message, DiagnosticIDs::Note);
}
}
}
diff --git a/clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp b/clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
index 68f4658a7dc9b..0c7a20ad6a179 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
@@ -27,8 +27,8 @@ void error() {
int ThreadID = get_local_id(0);
while (j < ThreadID) {
- // CHECK-NOTES: :[[@LINE-3]]:3: note: assignment of ID-dependent variable ThreadID
- // CHECK-NOTES: :[[@LINE-2]]:10: warning: backward branch (while loop) is ID-dependent due to variable reference to 'ThreadID' and may cause performance degradation [altera-id-dependent-backward-branch]
+ // CHECK-NOTES: :[[@LINE-1]]:10: warning: backward branch (while loop) is ID-dependent due to variable reference to 'ThreadID' and may cause performance degradation [altera-id-dependent-backward-branch]
+ // CHECK-NOTES: :[[@LINE-4]]:3: note: assignment of ID-dependent variable ThreadID
accumulator++;
}
@@ -45,34 +45,34 @@ void error() {
};
for (int i = 0; i < ThreadID2; i++) {
- // CHECK-NOTES: :[[@LINE-9]]:3: note: inferred assignment of ID-dependent value from ID-dependent variable ThreadID
- // CHECK-NOTES: :[[@LINE-2]]:19: warning: backward branch (for loop) is ID-dependent due to variable reference to 'ThreadID2' and may cause performance degradation [altera-id-dependent-backward-branch]
+ // CHECK-NOTES: :[[@LINE-1]]:19: warning: backward branch (for loop) is ID-dependent due to variable reference to 'ThreadID2' and may cause performance degradation [altera-id-dependent-backward-branch]
+ // CHECK-NOTES: :[[@LINE-10]]:3: note: inferred assignment of ID-dependent value from ID-dependent variable ThreadID
accumulator++;
}
do {
accumulator++;
} while (j < ThreadID);
- // CHECK-NOTES: :[[@LINE-29]]:3: note: assignment of ID-dependent variable ThreadID
- // CHECK-NOTES: :[[@LINE-2]]:12: warning: backward branch (do loop) is ID-dependent due to variable reference to 'ThreadID' and may cause performance degradation [altera-id-dependent-backward-branch]
+ // CHECK-NOTES: :[[@LINE-1]]:12: warning: backward branch (do loop) is ID-dependent due to variable reference to 'ThreadID' and may cause performance degradation [altera-id-dependent-backward-branch]
+ // CHECK-NOTES: :[[@LINE-30]]:3: note: assignment of ID-dependent variable ThreadID
for (int i = 0; i < Example.IDDepField; i++) {
- // CHECK-NOTES: :[[@LINE-24]]:3: note: assignment of ID-dependent field IDDepField
- // CHECK-NOTES: :[[@LINE-2]]:19: warning: backward branch (for loop) is ID-dependent due to member reference to 'IDDepField' and may cause performance degradation [altera-id-dependent-backward-branch]
+ // CHECK-NOTES: :[[@LINE-1]]:19: warning: backward branch (for loop) is ID-dependent due to member reference to 'IDDepField' and may cause performance degradation [altera-id-dependent-backward-branch]
+ // CHECK-NOTES: :[[@LINE-25]]:3: note: assignment of ID-dependent field IDDepField
accumulator++;
}
while (j < Example.IDDepField) {
- // CHECK-NOTES: :[[@LINE-30]]:3: note: assignment of ID-dependent field IDDepField
- // CHECK-NOTES: :[[@LINE-2]]:10: warning: backward branch (while loop) is ID-dependent due to member reference to 'IDDepField' and may cause performance degradation [altera-id-dependent-backward-branch]
+ // CHECK-NOTES: :[[@LINE-1]]:10: warning: backward branch (while loop) is ID-dependent due to member reference to 'IDDepField' and may cause performance degradation [altera-id-dependent-backward-branch]
+ // CHECK-NOTES: :[[@LINE-31]]:3: note: assignment of ID-dependent field IDDepField
accumulator++;
}
do {
accumulator++;
} while (j < Example.IDDepField);
- // CHECK-NOTES: :[[@LINE-38]]:3: note: assignment of ID-dependent field IDDepField
- // CHECK-NOTES: :[[@LINE-2]]:12: warning: backward branch (do loop) is ID-dependent due to member reference to 'IDDepField' and may cause performance degradation [altera-id-dependent-backward-branch]
+ // CHECK-NOTES: :[[@LINE-1]]:12: warning: backward branch (do loop) is ID-dependent due to member reference to 'IDDepField' and may cause performance degradation [altera-id-dependent-backward-branch]
+ // CHECK-NOTES: :[[@LINE-39]]:3: note: assignment of ID-dependent field IDDepField
}
void success() {
More information about the cfe-commits
mailing list