[clang] 32efb81 - [analyzer] [NFC] Simplify SVal::getAsLocSymbol function using existing functions

Denys Petrov via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 26 08:00:42 PDT 2020


Author: Denys Petrov
Date: 2020-10-26T17:00:29+02:00
New Revision: 32efb81ea60a9e99571923bf9308598f6cd341f2

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

LOG: [analyzer] [NFC] Simplify SVal::getAsLocSymbol function using existing functions

Summary: Method of obtaining MemRegion from LocAsInteger/MemRegionVal already exists in SVal::getAsRegion function. Replace repetitive conditions in SVal::getAsLocSymbol with SVal::getAsRegion function.

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

Added: 
    

Modified: 
    clang/lib/StaticAnalyzer/Core/SVals.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/StaticAnalyzer/Core/SVals.cpp b/clang/lib/StaticAnalyzer/Core/SVals.cpp
index c4d5377f3bae..252596887e4f 100644
--- a/clang/lib/StaticAnalyzer/Core/SVals.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SVals.cpp
@@ -84,16 +84,12 @@ const FunctionDecl *SVal::getAsFunctionDecl() const {
 /// the first symbolic parent region is returned.
 SymbolRef SVal::getAsLocSymbol(bool IncludeBaseRegions) const {
   // FIXME: should we consider SymbolRef wrapped in CodeTextRegion?
-  if (Optional<nonloc::LocAsInteger> X = getAs<nonloc::LocAsInteger>())
-    return X->getLoc().getAsLocSymbol(IncludeBaseRegions);
-
-  if (Optional<loc::MemRegionVal> X = getAs<loc::MemRegionVal>()) {
-    const MemRegion *R = X->getRegion();
-    if (const SymbolicRegion *SymR = IncludeBaseRegions ?
-                                      R->getSymbolicBase() :
-                                      dyn_cast<SymbolicRegion>(R->StripCasts()))
+  if (const MemRegion *R = getAsRegion())
+    if (const SymbolicRegion *SymR =
+            IncludeBaseRegions ? R->getSymbolicBase()
+                               : dyn_cast<SymbolicRegion>(R->StripCasts()))
       return SymR->getSymbol();
-  }
+
   return nullptr;
 }
 


        


More information about the cfe-commits mailing list