Nathan-Huckleberry created this revision.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.

Lexer::getLocForEndOfToken is defined to return an
invalid location if the given location is inside a macro.
Other checks conditionally warn based off location
validity. Updating this check to do the same.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D64607

Files:
  clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp


Index: clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
@@ -132,9 +132,10 @@
           // We report the first occurence only when we find the second one.
           diag(Branches[i]->getBeginLoc(),
                "repeated branch in conditional chain");
-          diag(Lexer::getLocForEndOfToken(Branches[i]->getEndLoc(), 0,
-                                          *Result.SourceManager, 
getLangOpts()),
-               "end of the original", DiagnosticIDs::Note);
+          SourceLocation End = 
Lexer::getLocForEndOfToken(Branches[i]->getEndLoc(), 0, *Result.SourceManager, 
getLangOpts());
+          if(End.isValid()) {
+            diag(End,"end of the original", DiagnosticIDs::Note);
+          }
         }
 
         diag(Branches[j]->getBeginLoc(), "clone %0 starts here",
@@ -208,10 +209,11 @@
 
         if (EndLoc.isMacroID())
           EndLoc = Context.getSourceManager().getExpansionLoc(EndLoc);
+        EndLoc = Lexer::getLocForEndOfToken(EndLoc, 0, 
*Result.SourceManager,getLangOpts());
 
-        diag(Lexer::getLocForEndOfToken(EndLoc, 0, *Result.SourceManager,
-                                        getLangOpts()),
-             "last of these clones ends here", DiagnosticIDs::Note);
+        if(EndLoc.isValid()) {
+          diag(EndLoc,"last of these clones ends here", DiagnosticIDs::Note);
+        }
       }
       BeginCurrent = EndCurrent;
     }


Index: clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
+++ clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
@@ -132,9 +132,10 @@
           // We report the first occurence only when we find the second one.
           diag(Branches[i]->getBeginLoc(),
                "repeated branch in conditional chain");
-          diag(Lexer::getLocForEndOfToken(Branches[i]->getEndLoc(), 0,
-                                          *Result.SourceManager, getLangOpts()),
-               "end of the original", DiagnosticIDs::Note);
+          SourceLocation End = Lexer::getLocForEndOfToken(Branches[i]->getEndLoc(), 0, *Result.SourceManager, getLangOpts());
+          if(End.isValid()) {
+            diag(End,"end of the original", DiagnosticIDs::Note);
+          }
         }
 
         diag(Branches[j]->getBeginLoc(), "clone %0 starts here",
@@ -208,10 +209,11 @@
 
         if (EndLoc.isMacroID())
           EndLoc = Context.getSourceManager().getExpansionLoc(EndLoc);
+        EndLoc = Lexer::getLocForEndOfToken(EndLoc, 0, *Result.SourceManager,getLangOpts());
 
-        diag(Lexer::getLocForEndOfToken(EndLoc, 0, *Result.SourceManager,
-                                        getLangOpts()),
-             "last of these clones ends here", DiagnosticIDs::Note);
+        if(EndLoc.isValid()) {
+          diag(EndLoc,"last of these clones ends here", DiagnosticIDs::Note);
+        }
       }
       BeginCurrent = EndCurrent;
     }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to