[clang] c113cbb - [clang][Diagnostic][NFC] Simplify emitDiagnosticLoc

Timm Bäder via cfe-commits cfe-commits at lists.llvm.org
Wed May 31 00:50:41 PDT 2023


Author: Timm Bäder
Date: 2023-05-31T09:40:24+02:00
New Revision: c113cbb51005108d1380a4b9d501ddeb1366a406

URL: https://github.com/llvm/llvm-project/commit/c113cbb51005108d1380a4b9d501ddeb1366a406
DIFF: https://github.com/llvm/llvm-project/commit/c113cbb51005108d1380a4b9d501ddeb1366a406.diff

LOG: [clang][Diagnostic][NFC] Simplify emitDiagnosticLoc

We don't use the offset returned from SourceManager::getDecomposedLoc
here, so we might as well just use getFileID().

Differential Revision: https://reviews.llvm.org/D151093

Added: 
    

Modified: 
    clang/lib/Frontend/TextDiagnostic.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Frontend/TextDiagnostic.cpp b/clang/lib/Frontend/TextDiagnostic.cpp
index 930033a7d552..83f254f7de83 100644
--- a/clang/lib/Frontend/TextDiagnostic.cpp
+++ b/clang/lib/Frontend/TextDiagnostic.cpp
@@ -850,30 +850,26 @@ void TextDiagnostic::emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
   if (DiagOpts->ShowSourceRanges && !Ranges.empty()) {
     FileID CaretFileID = Loc.getExpansionLoc().getFileID();
     bool PrintedRange = false;
+    const SourceManager &SM = Loc.getManager();
 
     for (const auto &R : Ranges) {
       // Ignore invalid ranges.
       if (!R.isValid())
         continue;
 
-      auto &SM = Loc.getManager();
       SourceLocation B = SM.getExpansionLoc(R.getBegin());
       CharSourceRange ERange = SM.getExpansionRange(R.getEnd());
       SourceLocation E = ERange.getEnd();
-      bool IsTokenRange = ERange.isTokenRange();
 
-      std::pair<FileID, unsigned> BInfo = SM.getDecomposedLoc(B);
-      std::pair<FileID, unsigned> EInfo = SM.getDecomposedLoc(E);
-
-      // If the start or end of the range is in another file, just discard
-      // it.
-      if (BInfo.first != CaretFileID || EInfo.first != CaretFileID)
+      // If the start or end of the range is in another file, just
+      // discard it.
+      if (SM.getFileID(B) != CaretFileID || SM.getFileID(E) != CaretFileID)
         continue;
 
       // Add in the length of the token, so that we cover multi-char
       // tokens.
       unsigned TokSize = 0;
-      if (IsTokenRange)
+      if (ERange.isTokenRange())
         TokSize = Lexer::MeasureTokenLength(E, SM, LangOpts);
 
       FullSourceLoc BF(B, SM), EF(E, SM);


        


More information about the cfe-commits mailing list