From f9bb101d394d62027ba33e132691540f1e63cea8 Mon Sep 17 00:00:00 2001 From: Mehdi Amini Date: Wed, 3 Jun 2020 03:02:28 +0000 Subject: [PATCH] Revert "[NFC, StackSafety] Change type of internal container" This reverts commit f62813e7eae148a6175de28bfa384524a9f2bf94. GCC 5.3 build is broken. --- llvm/lib/Analysis/StackSafetyAnalysis.cpp | 37 +++++++++++++++-------- 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/llvm/lib/Analysis/StackSafetyAnalysis.cpp b/llvm/lib/Analysis/StackSafetyAnalysis.cpp index dafa06922906..60ed0ed161f0 100644 --- a/llvm/lib/Analysis/StackSafetyAnalysis.cpp +++ b/llvm/lib/Analysis/StackSafetyAnalysis.cpp @@ -140,7 +140,7 @@ ConstantRange getStaticAllocaSizeRange(const AllocaInst &AI) { } struct FunctionInfo { - std::map Allocas; + SmallVector Allocas; SmallVector Params; // TODO: describe return value as depending on one or more of its arguments. @@ -165,11 +165,13 @@ struct FunctionInfo { O << " allocas uses:\n"; if (F) { + size_t Pos = 0; for (auto &I : instructions(F)) { if (const AllocaInst *AI = dyn_cast(&I)) { - auto &AS = Allocas.find(AI)->second; + auto &AS = Allocas[Pos]; O << " " << AI->getName() << "[" << getStaticAllocaSizeRange(*AI).getUpper() << "]: " << AS << "\n"; + ++Pos; } } } else { @@ -389,7 +391,8 @@ FunctionInfo StackSafetyLocalAnalysis::run() { for (auto &I : instructions(F)) { if (auto *AI = dyn_cast(&I)) { - UseInfo &AS = Info.Allocas.emplace(AI, PointerSize).first->second; + Info.Allocas.emplace_back(PointerSize); + UseInfo &AS = Info.Allocas.back(); analyzeAllUses(AI, AS); } } @@ -599,18 +602,19 @@ GVToSSI createGlobalStackSafetyInfo( for (auto &F : SSDFA.run()) { auto FI = F.second; + size_t Pos = 0; auto &SrcF = Functions[F.first]; - for (auto &KV : FI.Allocas) { - auto &A = KV.second; + for (auto &A : FI.Allocas) { resolveAllCalls(A); for (auto &C : A.Calls) { A.updateRange( SSDFA.getArgumentAccessRange(C.Callee, C.ParamNo, C.Offset)); } // FIXME: This is needed only to preserve calls in print() results. - A.Calls = SrcF.Allocas.find(KV.first)->second.Calls; + A.Calls = SrcF.Allocas[Pos].Calls; + ++Pos; } - size_t Pos = 0; + Pos = 0; for (auto &P : FI.Params) { P.Calls = SrcF.Params[Pos].Calls; ++Pos; @@ -658,11 +662,20 @@ const StackSafetyGlobalInfo::InfoTy &StackSafetyGlobalInfo::getInfo() const { } Info.reset( new InfoTy{createGlobalStackSafetyInfo(std::move(Functions)), {}}); - for (auto &FnKV : Info->Info) { - for (auto &KV : FnKV.second.Allocas) { - const AllocaInst *AI = KV.first; - if (getStaticAllocaSizeRange(*AI).contains(KV.second.Range)) - Info->SafeAllocas.insert(AI); + for (auto &KV : Info->Info) { + if (!KV.first->isDeclaration()) { + size_t Pos = 0; + // FIXME: Convert FunctionInfo::Allocas into map + // and do not rely on alloca index. + for (auto &I : instructions(*cast(KV.first))) { + if (const auto &AI = dyn_cast(&I)) { + if (getStaticAllocaSizeRange(*AI).contains( + KV.second.Allocas[Pos].Range)) { + Info->SafeAllocas.insert(AI); + } + ++Pos; + } + } } } if (StackSafetyPrint)