Use range-based for loops in ASan, TSan and MSan

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209834 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alexey Samsonov
2014-05-29 18:40:48 +00:00
parent fa68048322
commit d4d04199ac
3 changed files with 81 additions and 97 deletions

View File

@ -333,20 +333,17 @@ bool ThreadSanitizer::runOnFunction(Function &F) {
bool HasCalls = false;
// Traverse all instructions, collect loads/stores/returns, check for calls.
for (Function::iterator FI = F.begin(), FE = F.end();
FI != FE; ++FI) {
BasicBlock &BB = *FI;
for (BasicBlock::iterator BI = BB.begin(), BE = BB.end();
BI != BE; ++BI) {
if (isAtomic(BI))
AtomicAccesses.push_back(BI);
else if (isa<LoadInst>(BI) || isa<StoreInst>(BI))
LocalLoadsAndStores.push_back(BI);
else if (isa<ReturnInst>(BI))
RetVec.push_back(BI);
else if (isa<CallInst>(BI) || isa<InvokeInst>(BI)) {
if (isa<MemIntrinsic>(BI))
MemIntrinCalls.push_back(BI);
for (auto &BB : F) {
for (auto &Inst : BB) {
if (isAtomic(&Inst))
AtomicAccesses.push_back(&Inst);
else if (isa<LoadInst>(Inst) || isa<StoreInst>(Inst))
LocalLoadsAndStores.push_back(&Inst);
else if (isa<ReturnInst>(Inst))
RetVec.push_back(&Inst);
else if (isa<CallInst>(Inst) || isa<InvokeInst>(Inst)) {
if (isa<MemIntrinsic>(Inst))
MemIntrinCalls.push_back(&Inst);
HasCalls = true;
chooseInstructionsToInstrument(LocalLoadsAndStores, AllLoadsAndStores);
}
@ -360,19 +357,19 @@ bool ThreadSanitizer::runOnFunction(Function &F) {
// Instrument memory accesses.
if (ClInstrumentMemoryAccesses && F.hasFnAttribute(Attribute::SanitizeThread))
for (size_t i = 0, n = AllLoadsAndStores.size(); i < n; ++i) {
Res |= instrumentLoadOrStore(AllLoadsAndStores[i]);
for (auto Inst : AllLoadsAndStores) {
Res |= instrumentLoadOrStore(Inst);
}
// Instrument atomic memory accesses.
if (ClInstrumentAtomics)
for (size_t i = 0, n = AtomicAccesses.size(); i < n; ++i) {
Res |= instrumentAtomic(AtomicAccesses[i]);
for (auto Inst : AtomicAccesses) {
Res |= instrumentAtomic(Inst);
}
if (ClInstrumentMemIntrinsics)
for (size_t i = 0, n = MemIntrinCalls.size(); i < n; ++i) {
Res |= instrumentMemIntrinsic(MemIntrinCalls[i]);
for (auto Inst : MemIntrinCalls) {
Res |= instrumentMemIntrinsic(Inst);
}
// Instrument function entry/exit points if there were instrumented accesses.
@ -382,8 +379,8 @@ bool ThreadSanitizer::runOnFunction(Function &F) {
Intrinsic::getDeclaration(F.getParent(), Intrinsic::returnaddress),
IRB.getInt32(0));
IRB.CreateCall(TsanFuncEntry, ReturnAddress);
for (size_t i = 0, n = RetVec.size(); i < n; ++i) {
IRBuilder<> IRBRet(RetVec[i]);
for (auto RetInst : RetVec) {
IRBuilder<> IRBRet(RetInst);
IRBRet.CreateCall(TsanFuncExit);
}
Res = true;