[clang][dataflow] Eliminate code duplication in Environment::createValueUnlessSelfRef...
authorMartin Braenne <mboehme@google.com>
Wed, 5 Apr 2023 11:20:33 +0000 (11:20 +0000)
committerMartin Braenne <mboehme@google.com>
Thu, 6 Apr 2023 07:01:44 +0000 (07:01 +0000)
Reviewed By: sammccall

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

clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp

index faeabdc..ee8f6c5 100644 (file)
@@ -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()) {