From 6c7a0bc3d964d4e0840f82db692e3b88c9eb1f33 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Fri, 16 Sep 2016 01:38:46 +0000 Subject: Revert "[asan] Avoid lifetime analysis for allocas with can be in ambiguous state" This approach is not good enough. Working on the new solution. This reverts commit r280907. llvm-svn: 281689 --- .../Instrumentation/AddressSanitizer.cpp | 75 ---------------------- 1 file changed, 75 deletions(-) (limited to 'llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp') diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 729dc7c5567..aef47aa3741 100644 --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -833,77 +833,6 @@ struct FunctionStackPoisoner : public InstVisitor { Instruction *ThenTerm, Value *ValueIfFalse); }; -// Performs depth-first search on the control flow graph of block and checks if -// we can get into the same block with different lifetime state. -class AllocaLifetimeChecker { - // Contains values of the last lifetime intrinsics in the block. - // true: llvm.lifetime.start, false: llvm.lifetime.end - DenseMap Markers; - // Contains the lifetime state we detected doing depth-first search on the - // control flow graph. We expect all future hits will have the same value. - // true: llvm.lifetime.start, false: llvm.lifetime.end - DenseMap InboundState; - bool Processed = false; - bool CollisionDetected = false; - - bool FindCollision(const std::pair &BlockState) { - auto Ins = InboundState.insert(BlockState); - if (!Ins.second) { - // Already there. Return collision if they are different. - return BlockState.second != Ins.first->second; - } - - // Use marker for successors if block contains any. - auto M = Markers.find(BlockState.first); - bool NewState = (M != Markers.end() ? M->second : BlockState.second); - for (const BasicBlock *SB : successors(BlockState.first)) - // We may get into EHPad with any lifetime state, so ignore them. - if (!SB->isEHPad() && FindCollision({SB, NewState})) - return true; - - return false; - } - -public: - // Assume that markers of the same block will be added in the same order as - // the order of corresponding intrinsics, so in the end we will keep only - // value of the last intrinsic. - void AddMarker(const BasicBlock *BB, bool start) { - assert(!Processed); - Markers[BB] = start; - } - - bool HasAmbiguousLifetime() { - if (!Processed) { - Processed = true; - const Function *F = Markers.begin()->first->getParent(); - CollisionDetected = FindCollision({&F->getEntryBlock(), false}); - } - return CollisionDetected; - } -}; - -// Removes allocas for which exists at least one block simultaneously -// reachable in both states: allocas is inside the scope, and alloca is outside -// of the scope. We don't have enough information to validate access to such -// variable, so we just remove such allocas from lifetime analysis. -// This is workaround for PR28267. -void removeAllocasWithAmbiguousLifetime( - SmallVectorImpl &PoisonCallVec) { - DenseMap Checkers; - for (const auto &APC : PoisonCallVec) - Checkers[APC.AI].AddMarker(APC.InsBefore->getParent(), !APC.DoPoison); - - auto IsAmbiguous = - [&Checkers](const FunctionStackPoisoner::AllocaPoisonCall &APC) { - return Checkers[APC.AI].HasAmbiguousLifetime(); - }; - - PoisonCallVec.erase( - std::remove_if(PoisonCallVec.begin(), PoisonCallVec.end(), IsAmbiguous), - PoisonCallVec.end()); -} - } // anonymous namespace char AddressSanitizer::ID = 0; @@ -2191,8 +2120,6 @@ void FunctionStackPoisoner::processDynamicAllocas() { return; } - removeAllocasWithAmbiguousLifetime(DynamicAllocaPoisonCallVec); - // Insert poison calls for lifetime intrinsics for dynamic allocas. for (const auto &APC : DynamicAllocaPoisonCallVec) { assert(APC.InsBefore); @@ -2220,8 +2147,6 @@ void FunctionStackPoisoner::processStaticAllocas() { return; } - removeAllocasWithAmbiguousLifetime(StaticAllocaPoisonCallVec); - int StackMallocIdx = -1; DebugLoc EntryDebugLocation; if (auto SP = F.getSubprogram()) -- cgit v1.2.3