[llvm-branch-commits] [clang] 9f76788 - [clang][Sema] Compare SourceLocations directly [NFCI]

Mikhail Maltsev via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Jan 9 06:18:29 PST 2021


Author: Mikhail Maltsev
Date: 2021-01-09T14:13:18Z
New Revision: 9f76788b0930ed48f5f20a25f1b30d63c8486531

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

LOG: [clang][Sema] Compare SourceLocations directly [NFCI]

The ordered comparison operators are defined for the SourceLocation
class, so SourceLocation objects can be compared directly. There is no
need to extract the internal representation for comparison.

Reviewed By: aprantl

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

Added: 
    

Modified: 
    clang/lib/Sema/SemaDecl.cpp
    clang/lib/Sema/SemaStmt.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3a1294ce431f..dd31f3f98487 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -436,9 +436,7 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc,
          Res != ResEnd; ++Res) {
       if (isa<TypeDecl>(*Res) || isa<ObjCInterfaceDecl>(*Res) ||
           (AllowDeducedTemplate && getAsTypeTemplateDecl(*Res))) {
-        if (!IIDecl ||
-            (*Res)->getLocation().getRawEncoding() <
-              IIDecl->getLocation().getRawEncoding())
+        if (!IIDecl || (*Res)->getLocation() < IIDecl->getLocation())
           IIDecl = *Res;
       }
     }

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index a47fdf625bba..b24a8ab110b2 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -672,8 +672,7 @@ static bool CmpCaseVals(const std::pair<llvm::APSInt, CaseStmt*>& lhs,
     return true;
 
   if (lhs.first == rhs.first &&
-      lhs.second->getCaseLoc().getRawEncoding()
-       < rhs.second->getCaseLoc().getRawEncoding())
+      lhs.second->getCaseLoc() < rhs.second->getCaseLoc())
     return true;
   return false;
 }


        


More information about the llvm-branch-commits mailing list