[PATCH] D145303: clang-tidy altera-id-dependent-backward-branch: print notes after warning

Carlos Galvez via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 5 08:07:09 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rGc6d195b366c8: clang-tidy altera-id-dependent-backward-branch: print notes after warning (authored by yeputons-gh, committed by carlosgalvezp).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D145303/new/

https://reviews.llvm.org/D145303

Files:
  clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
  clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp


Index: clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/altera/id-dependent-backward-branch.cpp
@@ -27,8 +27,8 @@
   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 @@
   };
 
   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() {
Index: clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
+++ clang-tools-extra/clang-tidy/altera/IdDependentBackwardBranchCheck.cpp
@@ -241,18 +241,17 @@
     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);
     }
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145303.502435.patch
Type: text/x-patch
Size: 5755 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230305/2943556b/attachment.bin>


More information about the cfe-commits mailing list