diff options
author | Florian Mayer <fmayer@google.com> | 2021-09-15 10:10:11 +0100 |
---|---|---|
committer | Florian Mayer <fmayer@google.com> | 2021-09-22 11:08:27 +0100 |
commit | 36daf074d997a79f25a1de2a1b869170ea6c20cc (patch) | |
tree | fa302d23a1e4c93d36a945c6263a2bee420944e4 /llvm/lib/Analysis/StackSafetyAnalysis.cpp | |
parent | 4ca1fbe361860976646ad09da26757bf32563145 (diff) | |
download | llvm-36daf074d997a79f25a1de2a1b869170ea6c20cc.zip llvm-36daf074d997a79f25a1de2a1b869170ea6c20cc.tar.gz llvm-36daf074d997a79f25a1de2a1b869170ea6c20cc.tar.bz2 |
[hwasan] also omit safe mem[cpy|mov|set].
Reviewed By: eugenis
Differential Revision: https://reviews.llvm.org/D109816
Diffstat (limited to 'llvm/lib/Analysis/StackSafetyAnalysis.cpp')
-rw-r--r-- | llvm/lib/Analysis/StackSafetyAnalysis.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/llvm/lib/Analysis/StackSafetyAnalysis.cpp b/llvm/lib/Analysis/StackSafetyAnalysis.cpp index 0e981d1..44f8a18 100644 --- a/llvm/lib/Analysis/StackSafetyAnalysis.cpp +++ b/llvm/lib/Analysis/StackSafetyAnalysis.cpp @@ -230,7 +230,7 @@ struct StackSafetyInfo::InfoTy { struct StackSafetyGlobalInfo::InfoTy { GVToSSI Info; SmallPtrSet<const AllocaInst *, 8> SafeAllocas; - SmallPtrSet<const Instruction *, 8> SafeAccesses; + std::map<const Instruction *, bool> AccessIsUnsafe; }; namespace { @@ -820,7 +820,6 @@ const StackSafetyGlobalInfo::InfoTy &StackSafetyGlobalInfo::getInfo() const { Info.reset(new InfoTy{ createGlobalStackSafetyInfo(std::move(Functions), Index), {}, {}}); - std::map<const Instruction *, bool> AccessIsUnsafe; for (auto &FnKV : Info->Info) { for (auto &KV : FnKV.second.Allocas) { ++NumAllocaTotal; @@ -831,14 +830,10 @@ const StackSafetyGlobalInfo::InfoTy &StackSafetyGlobalInfo::getInfo() const { ++NumAllocaStackSafe; } for (const auto &A : KV.second.Accesses) - AccessIsUnsafe[A.first] |= !AIRange.contains(A.second); + Info->AccessIsUnsafe[A.first] |= !AIRange.contains(A.second); } } - for (const auto &KV : AccessIsUnsafe) - if (!KV.second) - Info->SafeAccesses.insert(KV.first); - if (StackSafetyPrint) print(errs()); } @@ -908,9 +903,13 @@ bool StackSafetyGlobalInfo::isSafe(const AllocaInst &AI) const { return Info.SafeAllocas.count(&AI); } -bool StackSafetyGlobalInfo::accessIsSafe(const Instruction &I) const { +bool StackSafetyGlobalInfo::stackAccessIsSafe(const Instruction &I) const { const auto &Info = getInfo(); - return Info.SafeAccesses.count(&I); + auto It = Info.AccessIsUnsafe.find(&I); + if (It == Info.AccessIsUnsafe.end()) { + return true; + } + return !It->second; } void StackSafetyGlobalInfo::print(raw_ostream &O) const { @@ -924,7 +923,10 @@ void StackSafetyGlobalInfo::print(raw_ostream &O) const { O << " safe accesses:" << "\n"; for (const auto &I : instructions(F)) { - if (accessIsSafe(I)) { + const CallInst *Call = dyn_cast<CallInst>(&I); + if ((isa<StoreInst>(I) || isa<LoadInst>(I) || isa<MemIntrinsic>(I) || + (Call && Call->hasByValArgument())) && + stackAccessIsSafe(I)) { O << " " << I << "\n"; } } |