Skip to content

Commit

Permalink
clang-tidy altera-id-dependent-backward-branch: print notes after war…
Browse files Browse the repository at this point in the history
…ning

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
  • Loading branch information
yeputons authored and carlosgalvezp committed Mar 5, 2023
1 parent bbda411 commit c6d195b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
Expand Up @@ -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);
}
}
}
Expand Down
Expand Up @@ -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++;
}

Expand All @@ -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() {
Expand Down

0 comments on commit c6d195b

Please sign in to comment.