diff --git a/binaryfile.cpp b/binaryfile.cpp index 616f906f6..9d19f5b0c 100644 --- a/binaryfile.cpp +++ b/binaryfile.cpp @@ -538,9 +538,10 @@ void BinaryFile::parseELF(object::ObjectFile *TheBinary, if (DynstrPortion.isAvailable()) { StringRef Dynstr = DynstrPortion.extractString(Segments); - for(auto Offset : NeededLibraryNameOffsets) - NeededLibraryNames.push_back(Dynstr.slice(Offset, - Dynstr.size()).data()); + for(auto Offset : NeededLibraryNameOffsets) { + StringRef LibraryName = Dynstr.slice(Offset, Dynstr.size()); + NeededLibraryNames.push_back(LibraryName.data()); + } } // Collect symbols count and code pointers in image base-relative diff --git a/functioncallidentification.cpp b/functioncallidentification.cpp index 8225ef049..101d89e51 100644 --- a/functioncallidentification.cpp +++ b/functioncallidentification.cpp @@ -40,9 +40,9 @@ bool FunctionCallIdentification::runOnFunction(llvm::Function &F) { PCPtrTy }; using FT = FunctionType; - auto *FunctionCallFT = FT::get(Type::getVoidTy(C), FunctionArgsTy, false); - FunctionCall = cast(M->getOrInsertFunction("function_call", - FunctionCallFT)); + auto *Ty = FT::get(Type::getVoidTy(C), FunctionArgsTy, false); + Constant *FunctionCallC = M->getOrInsertFunction("function_call", Ty); + FunctionCall = cast(FunctionCallC); // Initialize the function, if necessary if (FunctionCall->empty()) { diff --git a/jumptargetmanager.cpp b/jumptargetmanager.cpp index 9f782b896..7fb7a2594 100644 --- a/jumptargetmanager.cpp +++ b/jumptargetmanager.cpp @@ -982,9 +982,10 @@ void JumpTargetManager::translateIndirectJumps() { // Look for the last write to the PC StoreInst *PCWrite = getPrevPCWrite(Call); - assert((PCWrite == nullptr - || !isa(PCWrite->getValueOperand())) - && "Direct jumps should not be handled here"); + if (PCWrite != nullptr) { + assert(!isa(PCWrite->getValueOperand()) + && "Direct jumps should not be handled here"); + } if (PCWrite != nullptr && EnableOSRA && isSumJump(PCWrite)) handleSumJump(PCWrite); diff --git a/lazysmallbitvector.h b/lazysmallbitvector.h index caa864b6a..361ddae41 100644 --- a/lazysmallbitvector.h +++ b/lazysmallbitvector.h @@ -315,8 +315,9 @@ public: const LargeStorage &OtherLarge = Other.getLarge(); const LargeStorage &ThisLarge = getLarge(); - unsigned Max = std::min(ThisLarge.capacity(), - OtherLarge.capacity()) / BitsPerPointer; + unsigned Max = std::min(ThisLarge.capacity(), OtherLarge.capacity()); + Max /= BitsPerPointer; + for (unsigned I = 0; I < Max; I++) if (ThisLarge.at(I) != OtherLarge.at(I)) return false; @@ -371,8 +372,8 @@ public: const LargeStorage &OtherLarge = Other.getLarge(); LargeStorage &ThisLarge = getLarge(); - unsigned Max = std::min(ThisLarge.capacity(), - OtherLarge.capacity()) / BitsPerPointer; + unsigned Max = std::min(ThisLarge.capacity(), OtherLarge.capacity()); + Max /= BitsPerPointer; for (unsigned I = 0; I < Max; I++) ThisLarge.at(I) = ThisLarge.at(I) ^ OtherLarge.at(I); @@ -399,8 +400,9 @@ public: const LargeStorage &OtherLarge = Other.getLarge(); LargeStorage &ThisLarge = getLarge(); - unsigned Max = std::min(ThisLarge.capacity(), - OtherLarge.capacity()) / BitsPerPointer; + unsigned Max = std::min(ThisLarge.capacity(), OtherLarge.capacity()); + Max /= BitsPerPointer; + for (unsigned I = 0; I < Max; I++) ThisLarge.at(I) = ThisLarge.at(I) | OtherLarge.at(I); diff --git a/lib/StackAnalysis/abiir.cpp b/lib/StackAnalysis/abiir.cpp index 6fcc87316..2b99eac8f 100644 --- a/lib/StackAnalysis/abiir.cpp +++ b/lib/StackAnalysis/abiir.cpp @@ -46,17 +46,17 @@ bool ABIFunction::verify() const { for (auto &Successor : BB.successors()) { auto SuccessorPredecessors = Successor->predecessors(); - if (std::find(SuccessorPredecessors.begin(), - SuccessorPredecessors.end(), - &BB) == SuccessorPredecessors.end()) + auto StartIt = SuccessorPredecessors.begin(); + auto EndIt = SuccessorPredecessors.end(); + if (std::find(StartIt, EndIt, &BB) == EndIt) return false; } for (auto &Predecessor : BB.predecessors()) { auto PredecessorSuccessors = Predecessor->successors(); - if (std::find(PredecessorSuccessors.begin(), - PredecessorSuccessors.end(), - &BB) == PredecessorSuccessors.end()) + auto StartIt = PredecessorSuccessors.begin(); + auto EndIt = PredecessorSuccessors.end(); + if (std::find(StartIt, EndIt, &BB) == EndIt) return false; } diff --git a/lib/StackAnalysis/interprocedural.cpp b/lib/StackAnalysis/interprocedural.cpp index 3f20a90b2..e39332777 100644 --- a/lib/StackAnalysis/interprocedural.cpp +++ b/lib/StackAnalysis/interprocedural.cpp @@ -666,12 +666,14 @@ FunctionsSummary ResultsPool::finalize(const Module *M) { // Collect, for each call site, all the slots std::map> FunctionCallSlots; - for (auto &P : FunctionCallRegisterArguments) - FunctionCallSlots[P.first.first].insert(ASSlot::create(CPU, - P.first.second)); - for (auto &P : FunctionCallReturnValues) - FunctionCallSlots[P.first.first].insert(ASSlot::create(CPU, - P.first.second)); + for (auto &P : FunctionCallRegisterArguments) { + auto Slot = ASSlot::create(CPU, P.first.second); + FunctionCallSlots[P.first.first].insert(Slot); + } + for (auto &P : FunctionCallReturnValues) { + auto Slot = ASSlot::create(CPU, P.first.second); + FunctionCallSlots[P.first.first].insert(Slot); + } // // Merge information about a function and all the call sites targeting it diff --git a/lib/StackAnalysis/intraprocedural.cpp b/lib/StackAnalysis/intraprocedural.cpp index e8d62a55b..3de91f0bb 100644 --- a/lib/StackAnalysis/intraprocedural.cpp +++ b/lib/StackAnalysis/intraprocedural.cpp @@ -617,9 +617,10 @@ Interrupt Analysis::handleTerminator(TerminatorInst *T, const ASSlot *StackPointerSlot = StackPointerValue.directContent(); + auto SP0 = ASID::stackID(); bool IsReadyToReturn = not (StackPointerSlot != nullptr - and StackPointerSlot->addressSpace() == ASID::stackID() - and StackPointerSlot->offset() < 0); + and StackPointerSlot->addressSpace() == SP0 + and StackPointerSlot->offset() < 0); if (IsReadyToReturn) SaTerminator << " IsReadyToReturn"; diff --git a/lib/StackAnalysis/stackanalysis.cpp b/lib/StackAnalysis/stackanalysis.cpp index 5fa84a4ef..3af738ed3 100644 --- a/lib/StackAnalysis/stackanalysis.cpp +++ b/lib/StackAnalysis/stackanalysis.cpp @@ -31,18 +31,20 @@ namespace StackAnalysis { template<> char StackAnalysis::ID = 0; -static llvm::RegisterPass> X("sa", - "Stack Analysis Pass", - true, - true); + +namespace { +const char *Name = "Stack Analysis Pass"; +static RegisterPass> X("sa", Name, true, true); +} template<> char StackAnalysis::ID = 0; -static llvm::RegisterPass> Y("sab", - "Stack Analysis Pass with ABI" - " Analysis", - true, - true); + +static RegisterPass> Y("sab", + "Stack Analysis Pass with ABI" + " Analysis", + true, + true); template bool StackAnalysis::runOnFunction(Function &F) { diff --git a/noreturnanalysis.cpp b/noreturnanalysis.cpp index e5a267f4e..9b15375fd 100644 --- a/noreturnanalysis.cpp +++ b/noreturnanalysis.cpp @@ -36,10 +36,8 @@ void NoReturnAnalysis::registerSyscalls(llvm::Function *F) { if (NoDCE == nullptr) { Type *VoidTy = Type::getVoidTy(M->getContext()); Type *SNRTy = SyscallNumberRegister->getType()->getPointerElementType(); - NoDCE = cast(M->getOrInsertFunction("nodce", - VoidTy, - SNRTy, - nullptr)); + auto *FunctionC = M->getOrInsertFunction("nodce", VoidTy, SNRTy, nullptr); + NoDCE = cast(FunctionC); } for (User *U : SyscallHandler->users()) { diff --git a/osra.cpp b/osra.cpp index ae880152b..7865a10b3 100644 --- a/osra.cpp +++ b/osra.cpp @@ -1160,16 +1160,16 @@ void OSRA::handleBranch(Instruction *I) { }; std::vector ConstraintsWL; + BasicBlock *Source = Branch->getParent(); if (!inBlackList(Branch->getSuccessor(0))) { - ConstraintsWL.push_back(WLEntry(Branch->getSuccessor(0), - Branch->getParent(), - BranchConstraints)); + BasicBlock *Successor = Branch->getSuccessor(0); + ConstraintsWL.push_back(WLEntry(Successor, Source, BranchConstraints)); } if (!inBlackList(Branch->getSuccessor(1))) { - ConstraintsWL.push_back(WLEntry(Branch->getSuccessor(1), - Branch->getParent(), - FlippedBranchConstraints)); + BasicBlock *Successor = Branch->getSuccessor(1); + auto FBC = FlippedBranchConstraints; + ConstraintsWL.push_back(WLEntry(Successor, Source, FBC)); } // TODO: can we do this in a DFA way? @@ -1273,12 +1273,15 @@ void OSRA::handleBranch(Instruction *I) { // Propagate the new constraints to the successors (except for the // dispatcher) - if (Entry.Constraints.size() != 0) - for (BasicBlock *Successor : successors(Entry.Target)) - if (BlockBlackList.find(Successor) == BlockBlackList.end()) - ConstraintsWL.push_back(WLEntry(Successor, - Entry.Target, - Entry.Constraints)); + if (Entry.Constraints.size() != 0) { + for (BasicBlock *Successor : successors(Entry.Target)) { + if (BlockBlackList.find(Successor) == BlockBlackList.end()) { + WLEntry Constraint(Successor, Entry.Target, Entry.Constraints); + ConstraintsWL.push_back(Constraint); + } + } + } + } } diff --git a/reachingdefinitions.cpp b/reachingdefinitions.cpp index d53828111..bb321cdb8 100644 --- a/reachingdefinitions.cpp +++ b/reachingdefinitions.cpp @@ -128,19 +128,13 @@ template class ReachingDefinitionsImplPass; -static RegisterPass Y1("crdp", - "Conditional" - " Reaching" - " Definitions Pass", - true, - true); +using RegisterCRDP = RegisterPass; +const char *CRDPDescription = "Conditional Reaching Definitions Pass"; +static RegisterCRDP Y1("crdp", CRDPDescription, true, true); -static RegisterPass Y2("crlp", - "Conditional" - " Reaching" - " Definitions Pass", - true, - true); +using RegisterCRLP = RegisterPass; +const char *CRLPDescription = "Conditional Reaching Definitions Pass"; +static RegisterCRLP Y2("crlp", CRLPDescription, true, true); // ConditionalReachingDefinitionsPass methods implementations diff --git a/set.cpp b/set.cpp index 2cf32f3a9..0ab06575e 100644 --- a/set.cpp +++ b/set.cpp @@ -488,10 +488,11 @@ bool SET::run() { V = handleInstruction(&Instr, V); } - if (IsPCStore && OS.hasTrackedValues()) - Jumps.push_back(SETPass::JumpInfo(Store, - OS.isApproximate(), - OS.trackedValues())); + if (IsPCStore && OS.hasTrackedValues()) { + bool IsApproximate = OS.isApproximate(); + Jumps.emplace_back(Store, IsApproximate, OS.trackedValues()); + } + } } diff --git a/variablemanager.cpp b/variablemanager.cpp index 4715fc0c6..d33fe0fc3 100644 --- a/variablemanager.cpp +++ b/variablemanager.cpp @@ -158,18 +158,16 @@ VariableManager::VariableManager(Module& TheModule, NoAliasMDKindID(TheModule.getMDKindID("noalias")), TargetArchitecture(TargetArchitecture) { - auto *CPUStateAliasDomain = MDNode::getDistinct(TheModule.getContext(), + LLVMContext &Context = TheModule.getContext(); + auto *CPUStateAliasDomain = MDNode::getDistinct(Context, ArrayRef()); - auto *Temporary = MDNode::get(TheModule.getContext(), ArrayRef()); - auto *CPUStateScope = MDNode::getDistinct(TheModule.getContext(), - ArrayRef({ - Temporary, - CPUStateAliasDomain - })); + auto *Temporary = MDNode::get(Context, ArrayRef()); + ArrayRef Arguments({ Temporary, CPUStateAliasDomain }); + auto *CPUStateScope = MDNode::getDistinct(Context, Arguments); CPUStateScope->replaceOperandWith(0, CPUStateScope); - CPUStateScopeSet = MDNode::get(TheModule.getContext(), + CPUStateScopeSet = MDNode::get(Context, ArrayRef({ CPUStateScope })); assert(ptc.initialized_env != nullptr); @@ -219,9 +217,8 @@ VariableManager::VariableManager(Module& TheModule, ElectionMapElement& It2) { return It1.second < It2.second; }; - CPUStateType = std::max_element(EnvElection.begin(), - EnvElection.end(), - Compare)->first; + auto Max = std::max_element(EnvElection.begin(), EnvElection.end(), Compare); + CPUStateType = Max->first; // Look for structures containing CPUStateType as a member and promove them // to CPUStateType. Basically this is a flexible way to keep track of the *CPU @@ -399,10 +396,13 @@ bool VariableManager::memcpyAtEnvOffset(llvm::IRBuilder<> &Builder, // Consider the case when there's simply nothing there (alignment space). if (EnvVar == nullptr) { - if (false and EnvIsSrc) { // TODO: remove "false and", but after adding type based stuff + // TODO: remove "false and", but after adding type based stuff + if (false and EnvIsSrc) { ConstantInt *ZeroByte = Builder.getInt8(0); - Value *NewAddress = Builder.CreateAdd(Builder.getInt64(Offset), OtherBasePtr); - Value *OtherPtr = Builder.CreateIntToPtr(NewAddress, Builder.getInt8Ty()->getPointerTo()); + ConstantInt *OffsetInt = Builder.getInt64(Offset); + Value *NewAddress = Builder.CreateAdd(OffsetInt, OtherBasePtr); + Type *Int8PtrTy = Builder.getInt8Ty()->getPointerTo(); + Value *OtherPtr = Builder.CreateIntToPtr(NewAddress, Int8PtrTy); Builder.CreateStore(ZeroByte, OtherPtr); OnlyPointersAndPadding = false; } @@ -411,7 +411,8 @@ bool VariableManager::memcpyAtEnvOffset(llvm::IRBuilder<> &Builder, } OnlyPointersAndPadding = false; - Value *NewAddress = Builder.CreateAdd(Builder.getInt64(Offset), OtherBasePtr); + ConstantInt *OffsetInt = Builder.getInt64(Offset); + Value *NewAddress = Builder.CreateAdd(OffsetInt, OtherBasePtr); Value *OtherPtr = Builder.CreateIntToPtr(NewAddress, EnvVar->getType()); Value *Dst = EnvIsSrc ? OtherPtr : EnvVar;