[clang] 3c8ead2 - [clang][dataflow] Eliminate code duplication in Environment::createValueUnlessSelfReferential().

Martin Braenne via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 6 00:01:53 PDT 2023


Author: Martin Braenne
Date: 2023-04-06T07:01:44Z
New Revision: 3c8ead2662ac4a223467007c340c9f9a4b2b38af

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

LOG: [clang][dataflow] Eliminate code duplication in Environment::createValueUnlessSelfReferential().

Reviewed By: sammccall

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

Added: 
    

Modified: 
    clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index faeabdcbeed66..ee8f6c5b8f574 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -688,9 +688,9 @@ Value *Environment::createValueUnlessSelfReferential(
     return &create<IntegerValue>();
   }
 
-  if (Type->isReferenceType()) {
+  if (Type->isReferenceType() || Type->isPointerType()) {
     CreatedValuesCount++;
-    QualType PointeeType = Type->castAs<ReferenceType>()->getPointeeType();
+    QualType PointeeType = Type->getPointeeType();
     auto &PointeeLoc = createStorageLocation(PointeeType);
 
     if (Visited.insert(PointeeType.getCanonicalType()).second) {
@@ -702,24 +702,10 @@ Value *Environment::createValueUnlessSelfReferential(
         setValue(PointeeLoc, *PointeeVal);
     }
 
-    return &create<ReferenceValue>(PointeeLoc);
-  }
-
-  if (Type->isPointerType()) {
-    CreatedValuesCount++;
-    QualType PointeeType = Type->castAs<PointerType>()->getPointeeType();
-    auto &PointeeLoc = createStorageLocation(PointeeType);
-
-    if (Visited.insert(PointeeType.getCanonicalType()).second) {
-      Value *PointeeVal = createValueUnlessSelfReferential(
-          PointeeType, Visited, Depth, CreatedValuesCount);
-      Visited.erase(PointeeType.getCanonicalType());
-
-      if (PointeeVal != nullptr)
-        setValue(PointeeLoc, *PointeeVal);
-    }
-
-    return &create<PointerValue>(PointeeLoc);
+    if (Type->isReferenceType())
+      return &create<ReferenceValue>(PointeeLoc);
+    else
+      return &create<PointerValue>(PointeeLoc);
   }
 
   if (Type->isStructureOrClassType() || Type->isUnionType()) {


        


More information about the cfe-commits mailing list