From 60d704ab4a019dda8630f85a12f52ac826732e77 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Tue, 25 Sep 2012 19:03:01 +0000 Subject: [PATCH] [analyzer] Calculate liveness for symbolic exprs as well as atomic symbols. No tests, but this allows the optimization of removing dead constraints. We can then add tests that we don't do this prematurely. Note: the added FIXME to investigate SymbolRegionValue liveness is tracked by . This patch does not change the existing behavior. llvm-svn: 164621 --- clang/lib/StaticAnalyzer/Core/SymbolManager.cpp | 68 +++++++++++++++---------- 1 file changed, 40 insertions(+), 28 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp b/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp index c21df4c..87b4ba3 100644 --- a/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp +++ b/clang/lib/StaticAnalyzer/Core/SymbolManager.cpp @@ -466,37 +466,49 @@ bool SymbolReaper::isLive(SymbolRef sym) { markDependentsLive(sym); return true; } - - if (const SymbolDerived *derived = dyn_cast(sym)) { - if (isLive(derived->getParentSymbol())) { - markLive(sym); - return true; - } - return false; - } - - if (const SymbolExtent *extent = dyn_cast(sym)) { - if (isLiveRegion(extent->getRegion())) { - markLive(sym); - return true; - } - return false; + + bool KnownLive; + + switch (sym->getKind()) { + case SymExpr::RegionValueKind: + // FIXME: We should be able to use isLiveRegion here (this behavior + // predates isLiveRegion), but doing so causes test failures. Investigate. + KnownLive = true; + break; + case SymExpr::ConjuredKind: + KnownLive = false; + break; + case SymExpr::DerivedKind: + KnownLive = isLive(cast(sym)->getParentSymbol()); + break; + case SymExpr::ExtentKind: + KnownLive = isLiveRegion(cast(sym)->getRegion()); + break; + case SymExpr::MetadataKind: + KnownLive = MetadataInUse.count(sym) && + isLiveRegion(cast(sym)->getRegion()); + if (KnownLive) + MetadataInUse.erase(sym); + break; + case SymExpr::SymIntKind: + KnownLive = isLive(cast(sym)->getLHS()); + break; + case SymExpr::IntSymKind: + KnownLive = isLive(cast(sym)->getRHS()); + break; + case SymExpr::SymSymKind: + KnownLive = isLive(cast(sym)->getLHS()) && + isLive(cast(sym)->getRHS()); + break; + case SymExpr::CastSymbolKind: + KnownLive = isLive(cast(sym)->getOperand()); + break; } - if (const SymbolMetadata *metadata = dyn_cast(sym)) { - if (MetadataInUse.count(sym)) { - if (isLiveRegion(metadata->getRegion())) { - markLive(sym); - MetadataInUse.erase(sym); - return true; - } - } - return false; - } + if (KnownLive) + markLive(sym); - // Interogate the symbol. It may derive from an input value to - // the analyzed function/method. - return isa(sym); + return KnownLive; } bool -- 2.7.4