Index: llvm/include/llvm-c/Core.h =================================================================== --- llvm/include/llvm-c/Core.h +++ llvm/include/llvm-c/Core.h @@ -1840,7 +1840,7 @@ * * @see llvm::User::getNumOperands() */ -int LLVMGetNumOperands(LLVMValueRef Val); +unsigned LLVMGetNumOperands(LLVMValueRef Val); /** * @} Index: llvm/include/llvm/IR/DIBuilder.h =================================================================== --- llvm/include/llvm/IR/DIBuilder.h +++ llvm/include/llvm/IR/DIBuilder.h @@ -181,7 +181,7 @@ DIFile *File); /// Create a single enumerator value. - DIEnumerator *createEnumerator(StringRef Name, APSInt Value); + DIEnumerator *createEnumerator(StringRef Name, const APSInt &Value); DIEnumerator *createEnumerator(StringRef Name, uint64_t Val, bool IsUnsigned = false); Index: llvm/include/llvm/IR/DiagnosticInfo.h =================================================================== --- llvm/include/llvm/IR/DiagnosticInfo.h +++ llvm/include/llvm/IR/DiagnosticInfo.h @@ -438,7 +438,7 @@ Argument(StringRef Key, unsigned long long N); Argument(StringRef Key, ElementCount EC); Argument(StringRef Key, bool B) : Key(Key), Val(B ? "true" : "false") {} - Argument(StringRef Key, DebugLoc dl); + Argument(StringRef Key, const DebugLoc &dl); Argument(StringRef Key, InstructionCost C); }; @@ -457,7 +457,7 @@ PassName(PassName), RemarkName(RemarkName) {} void insert(StringRef S); - void insert(Argument A); + void insert(const Argument &A); void insert(setIsVerbose V); void insert(setExtraArgs EA); Index: llvm/include/llvm/IR/Function.h =================================================================== --- llvm/include/llvm/IR/Function.h +++ llvm/include/llvm/IR/Function.h @@ -319,7 +319,7 @@ return getSubclassDataFromValue() & (1<<14); } const std::string &getGC() const; - void setGC(std::string Str); + void setGC(const std::string &Str); void clearGC(); /// Return the attribute list for this Function. Index: llvm/include/llvm/IR/IRPrintingPasses.h =================================================================== --- llvm/include/llvm/IR/IRPrintingPasses.h +++ llvm/include/llvm/IR/IRPrintingPasses.h @@ -56,7 +56,7 @@ public: PrintModulePass(); - PrintModulePass(raw_ostream &OS, const std::string &Banner = "", + PrintModulePass(raw_ostream &OS, std::string Banner = "", bool ShouldPreserveUseListOrder = false); PreservedAnalyses run(Module &M, AnalysisManager &); @@ -73,7 +73,7 @@ public: PrintFunctionPass(); - PrintFunctionPass(raw_ostream &OS, const std::string &Banner = ""); + PrintFunctionPass(raw_ostream &OS, std::string Banner = ""); PreservedAnalyses run(Function &F, AnalysisManager &); static bool isRequired() { return true; } Index: llvm/include/llvm/IR/InlineAsm.h =================================================================== --- llvm/include/llvm/IR/InlineAsm.h +++ llvm/include/llvm/IR/InlineAsm.h @@ -46,7 +46,7 @@ AsmDialect Dialect; bool CanThrow; - InlineAsm(FunctionType *Ty, const std::string &AsmString, + InlineAsm(FunctionType *Ty, std::string AsmString, const std::string &Constraints, bool hasSideEffects, bool isAlignStack, AsmDialect asmDialect, bool canThrow); Index: llvm/include/llvm/IR/LLVMContext.h =================================================================== --- llvm/include/llvm/IR/LLVMContext.h +++ llvm/include/llvm/IR/LLVMContext.h @@ -129,7 +129,7 @@ void getSyncScopeNames(SmallVectorImpl &SSNs) const; /// Define the GC for a function - void setGC(const Function &Fn, std::string GCName); + void setGC(const Function &Fn, const std::string &GCName); /// Return the GC for a function const std::string &getGC(const Function &Fn); Index: llvm/include/llvm/IR/LegacyPassManagers.h =================================================================== --- llvm/include/llvm/IR/LegacyPassManagers.h +++ llvm/include/llvm/IR/LegacyPassManagers.h @@ -431,7 +431,7 @@ /// isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions /// or higher is specified. - bool isPassDebuggingExecutionsOrMore() const; + static bool isPassDebuggingExecutionsOrMore(); private: void dumpAnalysisUsage(StringRef Msg, const Pass *P, Index: llvm/lib/IR/AsmWriter.cpp =================================================================== --- llvm/lib/IR/AsmWriter.cpp +++ llvm/lib/IR/AsmWriter.cpp @@ -352,12 +352,11 @@ // Scan the name to see if it needs quotes first. bool NeedsQuotes = isdigit(static_cast(Name[0])); if (!NeedsQuotes) { - for (unsigned i = 0, e = Name.size(); i != e; ++i) { + for (unsigned char C : Name) { // By making this unsigned, the value passed in to isalnum will always be // in the range 0-255. This is important when building with MSVC because // its implementation will assert. This situation can arise when dealing // with UTF-8 multibyte characters. - unsigned char C = Name[i]; if (!isalnum(static_cast(C)) && C != '-' && C != '.' && C != '_') { NeedsQuotes = true; @@ -440,7 +439,7 @@ class TypePrinting { public: - TypePrinting(const Module *M = nullptr) : DeferredM(M) {} + explicit TypePrinting(const Module *M = nullptr) : DeferredM(M) {} TypePrinting(const TypePrinting &) = delete; TypePrinting &operator=(const TypePrinting &) = delete; @@ -647,7 +646,7 @@ OS << '>'; } -AbstractSlotTrackerStorage::~AbstractSlotTrackerStorage() {} +AbstractSlotTrackerStorage::~AbstractSlotTrackerStorage() = default; namespace llvm { @@ -729,7 +728,7 @@ SlotTracker(const SlotTracker &) = delete; SlotTracker &operator=(const SlotTracker &) = delete; - ~SlotTracker() = default; + ~SlotTracker() override = default; void setProcessHook( std::function); @@ -1651,7 +1650,7 @@ bool Skip = true; const char *Sep; - FieldSeparator(const char *Sep = ", ") : Sep(Sep) {} + explicit FieldSeparator(const char *Sep = ", ") : Sep(Sep) {} }; raw_ostream &operator<<(raw_ostream &OS, FieldSeparator &FS) { Index: llvm/lib/IR/AttributeImpl.h =================================================================== --- llvm/lib/IR/AttributeImpl.h +++ llvm/lib/IR/AttributeImpl.h @@ -47,7 +47,7 @@ TypeAttrEntry, }; - AttributeImpl(AttrEntryKind KindID) : KindID(KindID) {} + explicit AttributeImpl(AttrEntryKind KindID) : KindID(KindID) {} public: // AttributesImpl is uniqued, these should not be available. @@ -121,7 +121,7 @@ : AttributeImpl(ID), Kind(Kind) {} public: - EnumAttributeImpl(Attribute::AttrKind Kind) + explicit EnumAttributeImpl(Attribute::AttrKind Kind) : AttributeImpl(EnumAttrEntry), Kind(Kind) { assert(Kind != Attribute::AttrKind::None && "Can't create a None attribute!"); @@ -155,7 +155,7 @@ } public: - StringAttributeImpl(StringRef Kind, StringRef Val = StringRef()) + explicit StringAttributeImpl(StringRef Kind, StringRef Val = StringRef()) : AttributeImpl(StringAttrEntry), KindSize(Kind.size()), ValSize(Val.size()) { char *TrailingString = getTrailingObjects(); @@ -219,7 +219,7 @@ DenseMap StringAttrs; - AttributeSetNode(ArrayRef Attrs); + explicit AttributeSetNode(ArrayRef Attrs); static AttributeSetNode *getSorted(LLVMContext &C, ArrayRef SortedAttrs); @@ -293,7 +293,7 @@ size_t numTrailingObjects(OverloadToken) { return NumAttrSets; } public: - AttributeListImpl(ArrayRef Sets); + explicit AttributeListImpl(ArrayRef Sets); // AttributesSetImpt is uniqued, these should not be available. AttributeListImpl(const AttributeListImpl &) = delete; Index: llvm/lib/IR/Attributes.cpp =================================================================== --- llvm/lib/IR/Attributes.cpp +++ llvm/lib/IR/Attributes.cpp @@ -657,11 +657,11 @@ } bool AttributeSet::hasAttribute(Attribute::AttrKind Kind) const { - return SetNode ? SetNode->hasAttribute(Kind) : false; + return SetNode != nullptr && SetNode->hasAttribute(Kind); } bool AttributeSet::hasAttribute(StringRef Kind) const { - return SetNode ? SetNode->hasAttribute(Kind) : false; + return SetNode != nullptr && SetNode->hasAttribute(Kind); } Attribute AttributeSet::getAttribute(Attribute::AttrKind Kind) const { Index: llvm/lib/IR/AutoUpgrade.cpp =================================================================== --- llvm/lib/IR/AutoUpgrade.cpp +++ llvm/lib/IR/AutoUpgrade.cpp @@ -576,7 +576,8 @@ F->arg_begin()->getType()); return true; } - static const Regex vldRegex("^arm\\.neon\\.vld([1234]|[234]lane)\\.v[a-z0-9]*$"); + static const Regex vldRegex( + R"(^arm\.neon\.vld([1234]|[234]lane)\.v[a-z0-9]*$)"); if (vldRegex.match(Name)) { auto fArgs = F->getFunctionType()->params(); SmallVector Tys(fArgs.begin(), fArgs.end()); @@ -589,7 +590,8 @@ "llvm." + Name + "." + Suffix, F->getParent()); return true; } - static const Regex vstRegex("^arm\\.neon\\.vst([1234]|[234]lane)\\.v[a-z0-9]*$"); + static const Regex vstRegex( + R"(^arm\.neon\.vst([1234]|[234]lane)\.v[a-z0-9]*$)"); if (vstRegex.match(Name)) { static const Intrinsic::ID StoreInts[] = {Intrinsic::arm_neon_vst1, Intrinsic::arm_neon_vst2, @@ -4346,7 +4348,7 @@ // folding and other libcall simplification. The nobuiltin attribute on the // callsite has the same effect. struct StrictFPUpgradeVisitor : public InstVisitor { - StrictFPUpgradeVisitor() {} + StrictFPUpgradeVisitor() = default; void visitCallBase(CallBase &Call) { if (!Call.isStrictFP()) Index: llvm/lib/IR/BuiltinGCs.cpp =================================================================== --- llvm/lib/IR/BuiltinGCs.cpp +++ llvm/lib/IR/BuiltinGCs.cpp @@ -53,7 +53,7 @@ /// while introducing only minor runtime overhead. class ShadowStackGC : public GCStrategy { public: - ShadowStackGC() {} + ShadowStackGC() = default; }; /// A GCStrategy which serves as an example for the usage of a statepoint based Index: llvm/lib/IR/Constants.cpp =================================================================== --- llvm/lib/IR/Constants.cpp +++ llvm/lib/IR/Constants.cpp @@ -1271,8 +1271,8 @@ if (V.empty()) return ConstantAggregateZero::get(Ty); - for (unsigned i = 0, e = V.size(); i != e; ++i) { - assert(V[i]->getType() == Ty->getElementType() && + for (auto *I : V) { + assert(I->getType() == Ty->getElementType() && "Wrong type in array element initializer"); } @@ -1339,12 +1339,12 @@ isZero = V[0]->isNullValue(); // PoisonValue inherits UndefValue, so its check is not necessary. if (isUndef || isZero) { - for (unsigned i = 0, e = V.size(); i != e; ++i) { - if (!V[i]->isNullValue()) + for (auto *I : V) { + if (!I->isNullValue()) isZero = false; - if (!isa(V[i])) + if (!isa(I)) isPoison = false; - if (isa(V[i]) || !isa(V[i])) + if (isa(I) || !isa(I)) isUndef = false; } } Index: llvm/lib/IR/Core.cpp =================================================================== --- llvm/lib/IR/Core.cpp +++ llvm/lib/IR/Core.cpp @@ -142,12 +142,12 @@ if (AttrKind == Attribute::AttrKind::ByVal) { // After r362128, byval attributes need to have a type attribute. Provide a // NULL one until a proper API is added for this. - return wrap(Attribute::getWithByValType(Ctx, NULL)); + return wrap(Attribute::getWithByValType(Ctx, nullptr)); } if (AttrKind == Attribute::AttrKind::StructRet) { // Same as byval. - return wrap(Attribute::getWithStructRetType(Ctx, NULL)); + return wrap(Attribute::getWithStructRetType(Ctx, nullptr)); } return wrap(Attribute::get(Ctx, AttrKind, Val)); @@ -1048,7 +1048,7 @@ unwrap(Val)->setOperand(Index, unwrap(Op)); } -int LLVMGetNumOperands(LLVMValueRef Val) { +unsigned LLVMGetNumOperands(LLVMValueRef Val) { Value *V = unwrap(Val); if (isa(V)) return LLVMGetMDNodeNumOperands(Val); Index: llvm/lib/IR/DIBuilder.cpp =================================================================== --- llvm/lib/IR/DIBuilder.cpp +++ llvm/lib/IR/DIBuilder.cpp @@ -254,7 +254,7 @@ Name); } -DIEnumerator *DIBuilder::createEnumerator(StringRef Name, APSInt Value) { +DIEnumerator *DIBuilder::createEnumerator(StringRef Name, const APSInt &Value) { assert(!Name.empty() && "Unable to create enumerator without name"); return DIEnumerator::get(VMContext, APInt(Value), Value.isUnsigned(), Name); } @@ -656,11 +656,11 @@ DITypeRefArray DIBuilder::getOrCreateTypeArray(ArrayRef Elements) { SmallVector Elts; - for (unsigned i = 0, e = Elements.size(); i != e; ++i) { - if (Elements[i] && isa(Elements[i])) - Elts.push_back(cast(Elements[i])); + for (auto *Element : Elements) { + if (isa_and_nonnull(Element)) + Elts.push_back(cast(Element)); else - Elts.push_back(Elements[i]); + Elts.push_back(Element); } return DITypeRefArray(MDNode::get(VMContext, Elts)); } Index: llvm/lib/IR/DebugInfo.cpp =================================================================== --- llvm/lib/IR/DebugInfo.cpp +++ llvm/lib/IR/DebugInfo.cpp @@ -194,7 +194,7 @@ if (auto *DVI = dyn_cast(&I)) processVariable(M, *DVI); - if (auto DbgLoc = I.getDebugLoc()) + if (const auto &DbgLoc = I.getDebugLoc()) processLocation(M, DbgLoc.get()); } @@ -524,7 +524,7 @@ // output of -gline-tables-only. public: - DebugTypeInfoRemoval(LLVMContext &C) + explicit DebugTypeInfoRemoval(LLVMContext &C) : EmptySubroutineType(DISubroutineType::get(C, DINode::FlagZero, 0, MDNode::get(C, {}))) {} Index: llvm/lib/IR/DiagnosticHandler.cpp =================================================================== --- llvm/lib/IR/DiagnosticHandler.cpp +++ llvm/lib/IR/DiagnosticHandler.cpp @@ -37,13 +37,13 @@ } }; -static PassRemarksOpt PassRemarksPassedOptLoc; -static PassRemarksOpt PassRemarksMissedOptLoc; -static PassRemarksOpt PassRemarksAnalysisOptLoc; +PassRemarksOpt PassRemarksPassedOptLoc; +PassRemarksOpt PassRemarksMissedOptLoc; +PassRemarksOpt PassRemarksAnalysisOptLoc; // -pass-remarks // Command line flag to enable emitOptimizationRemark() -static cl::opt> PassRemarks( +cl::opt> PassRemarks( "pass-remarks", cl::value_desc("pattern"), cl::desc("Enable optimization remarks from passes whose name match " "the given regular expression"), @@ -52,7 +52,7 @@ // -pass-remarks-missed // Command line flag to enable emitOptimizationRemarkMissed() -static cl::opt> PassRemarksMissed( +cl::opt> PassRemarksMissed( "pass-remarks-missed", cl::value_desc("pattern"), cl::desc("Enable missed optimization remarks from passes whose name match " "the given regular expression"), @@ -61,15 +61,14 @@ // -pass-remarks-analysis // Command line flag to enable emitOptimizationRemarkAnalysis() -static cl::opt> - PassRemarksAnalysis( - "pass-remarks-analysis", cl::value_desc("pattern"), - cl::desc( - "Enable optimization analysis remarks from passes whose name match " - "the given regular expression"), - cl::Hidden, cl::location(PassRemarksAnalysisOptLoc), cl::ValueRequired, - cl::ZeroOrMore); -} +cl::opt> PassRemarksAnalysis( + "pass-remarks-analysis", cl::value_desc("pattern"), + cl::desc( + "Enable optimization analysis remarks from passes whose name match " + "the given regular expression"), + cl::Hidden, cl::location(PassRemarksAnalysisOptLoc), cl::ValueRequired, + cl::ZeroOrMore); +} // namespace bool DiagnosticHandler::isAnalysisRemarkEnabled(StringRef PassName) const { return (PassRemarksAnalysisOptLoc.Pattern && Index: llvm/lib/IR/DiagnosticInfo.cpp =================================================================== --- llvm/lib/IR/DiagnosticInfo.cpp +++ llvm/lib/IR/DiagnosticInfo.cpp @@ -224,11 +224,13 @@ C.print(OS); } -DiagnosticInfoOptimizationBase::Argument::Argument(StringRef Key, DebugLoc Loc) +DiagnosticInfoOptimizationBase::Argument::Argument(StringRef Key, + const DebugLoc &Loc) : Key(std::string(Key)), Loc(Loc) { if (Loc) { Val = (Loc->getFilename() + ":" + Twine(Loc.getLine()) + ":" + - Twine(Loc.getCol())).str(); + Twine(Loc.getCol())) + .str(); } else { Val = ""; } @@ -374,7 +376,7 @@ Args.emplace_back(S); } -void DiagnosticInfoOptimizationBase::insert(Argument A) { +void DiagnosticInfoOptimizationBase::insert(const Argument &A) { Args.push_back(std::move(A)); } Index: llvm/lib/IR/Function.cpp =================================================================== --- llvm/lib/IR/Function.cpp +++ llvm/lib/IR/Function.cpp @@ -689,7 +689,7 @@ return getContext().getGC(*this); } -void Function::setGC(std::string Str) { +void Function::setGC(const std::string &Str) { setValueSubclassDataBit(14, !Str.empty()); getContext().setGC(*this, std::move(Str)); } @@ -1600,7 +1600,7 @@ } case IITDescriptor::VecElementArgument: { if (D.getArgumentNumber() >= ArgTys.size()) - return IsDeferredCheck ? true : DeferCheck(Ty); + return IsDeferredCheck || DeferCheck(Ty); auto *ReferenceType = dyn_cast(ArgTys[D.getArgumentNumber()]); return !ReferenceType || Ty != ReferenceType->getElementType(); } Index: llvm/lib/IR/GVMaterializer.cpp =================================================================== --- llvm/lib/IR/GVMaterializer.cpp +++ llvm/lib/IR/GVMaterializer.cpp @@ -14,4 +14,4 @@ #include "llvm/IR/GVMaterializer.h" using namespace llvm; -GVMaterializer::~GVMaterializer() {} +GVMaterializer::~GVMaterializer() = default; Index: llvm/lib/IR/IRBuilder.cpp =================================================================== --- llvm/lib/IR/IRBuilder.cpp +++ llvm/lib/IR/IRBuilder.cpp @@ -1253,8 +1253,8 @@ return CreateAlignmentAssumptionHelper(DL, PtrValue, Alignment, OffsetValue); } -IRBuilderDefaultInserter::~IRBuilderDefaultInserter() {} -IRBuilderCallbackInserter::~IRBuilderCallbackInserter() {} -IRBuilderFolder::~IRBuilderFolder() {} +IRBuilderDefaultInserter::~IRBuilderDefaultInserter() = default; +IRBuilderCallbackInserter::~IRBuilderCallbackInserter() = default; +IRBuilderFolder::~IRBuilderFolder() = default; void ConstantFolder::anchor() {} void NoFolder::anchor() {} Index: llvm/lib/IR/IRPrintingPasses.cpp =================================================================== --- llvm/lib/IR/IRPrintingPasses.cpp +++ llvm/lib/IR/IRPrintingPasses.cpp @@ -10,6 +10,8 @@ // //===----------------------------------------------------------------------===// +#include + #include "llvm/IR/IRPrintingPasses.h" #include "llvm/ADT/StringRef.h" #include "llvm/IR/Function.h" @@ -23,9 +25,9 @@ using namespace llvm; PrintModulePass::PrintModulePass() : OS(dbgs()) {} -PrintModulePass::PrintModulePass(raw_ostream &OS, const std::string &Banner, +PrintModulePass::PrintModulePass(raw_ostream &OS, std::string Banner, bool ShouldPreserveUseListOrder) - : OS(OS), Banner(Banner), + : OS(OS), Banner(std::move(Banner)), ShouldPreserveUseListOrder(ShouldPreserveUseListOrder) {} PreservedAnalyses PrintModulePass::run(Module &M, ModuleAnalysisManager &) { @@ -50,8 +52,8 @@ } PrintFunctionPass::PrintFunctionPass() : OS(dbgs()) {} -PrintFunctionPass::PrintFunctionPass(raw_ostream &OS, const std::string &Banner) - : OS(OS), Banner(Banner) {} +PrintFunctionPass::PrintFunctionPass(raw_ostream &OS, std::string Banner) + : OS(OS), Banner(std::move(Banner)) {} PreservedAnalyses PrintFunctionPass::run(Function &F, FunctionAnalysisManager &) { Index: llvm/lib/IR/InlineAsm.cpp =================================================================== --- llvm/lib/IR/InlineAsm.cpp +++ llvm/lib/IR/InlineAsm.cpp @@ -24,14 +24,15 @@ #include #include #include +#include using namespace llvm; -InlineAsm::InlineAsm(FunctionType *FTy, const std::string &asmString, +InlineAsm::InlineAsm(FunctionType *FTy, std::string asmString, const std::string &constraints, bool hasSideEffects, bool isAlignStack, AsmDialect asmDialect, bool canThrow) : Value(PointerType::getUnqual(FTy), Value::InlineAsmVal), - AsmString(asmString), Constraints(constraints), FTy(FTy), + AsmString(std::move(asmString)), Constraints(constraints), FTy(FTy), HasSideEffects(hasSideEffects), IsAlignStack(isAlignStack), Dialect(asmDialect), CanThrow(canThrow) { // Do various checks on the constraint string and type. @@ -166,7 +167,7 @@ assert(scInfo.MatchingInput >= 0); } else { if (ConstraintsSoFar[N].hasMatchingInput() && - (size_t)ConstraintsSoFar[N].MatchingInput != + static_cast(ConstraintsSoFar[N].MatchingInput) != ConstraintsSoFar.size()) return true; // Note that operand #n has a matching input. @@ -262,19 +263,20 @@ unsigned NumOutputs = 0, NumInputs = 0, NumClobbers = 0; unsigned NumIndirect = 0; - for (unsigned i = 0, e = Constraints.size(); i != e; ++i) { - switch (Constraints[i].Type) { + for (auto &Constraint : Constraints) { + switch (Constraint.Type) { case InlineAsm::isOutput: - if ((NumInputs-NumIndirect) != 0 || NumClobbers != 0) - return false; // outputs before inputs and clobbers. - if (!Constraints[i].isIndirect) { + if (NumInputs != NumIndirect || NumClobbers != 0) + return false; // outputs before inputs and clobbers. + if (!Constraint.isIndirect) { ++NumOutputs; break; } ++NumIndirect; LLVM_FALLTHROUGH; // We fall through for Indirect Outputs. case InlineAsm::isInput: - if (NumClobbers) return false; // inputs before clobbers. + if (NumClobbers) + return false; // inputs before clobbers. ++NumInputs; break; case InlineAsm::isClobber: Index: llvm/lib/IR/Instructions.cpp =================================================================== --- llvm/lib/IR/Instructions.cpp +++ llvm/lib/IR/Instructions.cpp @@ -2328,7 +2328,6 @@ } Src1Elts.setBit(i); Src1Identity &= (M == (i + NumSrcElts)); - continue; } assert((Src0Elts | Src1Elts | UndefElts).isAllOnesValue() && "unknown shuffle elements"); Index: llvm/lib/IR/LLVMContext.cpp =================================================================== --- llvm/lib/IR/LLVMContext.cpp +++ llvm/lib/IR/LLVMContext.cpp @@ -295,7 +295,7 @@ pImpl->getSyncScopeNames(SSNs); } -void LLVMContext::setGC(const Function &Fn, std::string GCName) { +void LLVMContext::setGC(const Function &Fn, const std::string &GCName) { auto It = pImpl->GCNames.find(&Fn); if (It == pImpl->GCNames.end()) { Index: llvm/lib/IR/LLVMContextImpl.h =================================================================== --- llvm/lib/IR/LLVMContextImpl.h +++ llvm/lib/IR/LLVMContextImpl.h @@ -80,7 +80,7 @@ KeyTy(const ArrayRef& E, bool P) : ETypes(E), isPacked(P) {} - KeyTy(const StructType *ST) + explicit KeyTy(const StructType *ST) : ETypes(ST->elements()), isPacked(ST->isPacked()) {} bool operator==(const KeyTy& that) const { @@ -132,7 +132,7 @@ KeyTy(const Type* R, const ArrayRef& P, bool V) : ReturnType(R), Params(P), isVarArg(V) {} - KeyTy(const FunctionType *FT) + explicit KeyTy(const FunctionType *FT) : ReturnType(FT->getReturnType()), Params(FT->params()), isVarArg(FT->isVarArg()) {} @@ -187,11 +187,11 @@ unsigned Hash; protected: - MDNodeOpsKey(ArrayRef Ops) + explicit MDNodeOpsKey(ArrayRef Ops) : RawOps(Ops), Hash(calculateHash(Ops)) {} template - MDNodeOpsKey(const NodeTy *N, unsigned Offset = 0) + explicit MDNodeOpsKey(const NodeTy *N, unsigned Offset = 0) : Ops(N->op_begin() + Offset, N->op_end()), Hash(N->getHash()) {} template @@ -240,8 +240,8 @@ /// Note that we don't need the is-function-local bit, since that's implicit in /// the operands. template <> struct MDNodeKeyImpl : MDNodeOpsKey { - MDNodeKeyImpl(ArrayRef Ops) : MDNodeOpsKey(Ops) {} - MDNodeKeyImpl(const MDTuple *N) : MDNodeOpsKey(N) {} + explicit MDNodeKeyImpl(ArrayRef Ops) : MDNodeOpsKey(Ops) {} + explicit MDNodeKeyImpl(const MDTuple *N) : MDNodeOpsKey(N) {} bool isKeyOf(const MDTuple *RHS) const { return compareOps(RHS); } @@ -264,7 +264,7 @@ Metadata *InlinedAt, bool ImplicitCode) : Line(Line), Column(Column), Scope(Scope), InlinedAt(InlinedAt), ImplicitCode(ImplicitCode) {} - MDNodeKeyImpl(const DILocation *L) + explicit MDNodeKeyImpl(const DILocation *L) : Line(L->getLine()), Column(L->getColumn()), Scope(L->getRawScope()), InlinedAt(L->getRawInlinedAt()), ImplicitCode(L->isImplicitCode()) {} @@ -286,7 +286,7 @@ MDNodeKeyImpl(unsigned Tag, MDString *Header, ArrayRef DwarfOps) : MDNodeOpsKey(DwarfOps), Tag(Tag), Header(Header) {} - MDNodeKeyImpl(const GenericDINode *N) + explicit MDNodeKeyImpl(const GenericDINode *N) : MDNodeOpsKey(N, 1), Tag(N->getTag()), Header(N->getRawHeader()) {} bool isKeyOf(const GenericDINode *RHS) const { @@ -311,7 +311,7 @@ Metadata *Stride) : CountNode(CountNode), LowerBound(LowerBound), UpperBound(UpperBound), Stride(Stride) {} - MDNodeKeyImpl(const DISubrange *N) + explicit MDNodeKeyImpl(const DISubrange *N) : CountNode(N->getRawCountNode()), LowerBound(N->getRawLowerBound()), UpperBound(N->getRawUpperBound()), Stride(N->getRawStride()) {} @@ -356,7 +356,7 @@ Metadata *Stride) : CountNode(CountNode), LowerBound(LowerBound), UpperBound(UpperBound), Stride(Stride) {} - MDNodeKeyImpl(const DIGenericSubrange *N) + explicit MDNodeKeyImpl(const DIGenericSubrange *N) : CountNode(N->getRawCountNode()), LowerBound(N->getRawLowerBound()), UpperBound(N->getRawUpperBound()), Stride(N->getRawStride()) {} @@ -382,11 +382,11 @@ bool IsUnsigned; MDNodeKeyImpl(APInt Value, bool IsUnsigned, MDString *Name) - : Value(Value), Name(Name), IsUnsigned(IsUnsigned) {} + : Value(std::move(Value)), Name(Name), IsUnsigned(IsUnsigned) {} MDNodeKeyImpl(int64_t Value, bool IsUnsigned, MDString *Name) : Value(APInt(64, Value, !IsUnsigned)), Name(Name), IsUnsigned(IsUnsigned) {} - MDNodeKeyImpl(const DIEnumerator *N) + explicit MDNodeKeyImpl(const DIEnumerator *N) : Value(N->getValue()), Name(N->getRawName()), IsUnsigned(N->isUnsigned()) {} @@ -410,16 +410,16 @@ uint32_t AlignInBits, unsigned Encoding, unsigned Flags) : Tag(Tag), Name(Name), SizeInBits(SizeInBits), AlignInBits(AlignInBits), Encoding(Encoding), Flags(Flags) {} - MDNodeKeyImpl(const DIBasicType *N) + explicit MDNodeKeyImpl(const DIBasicType *N) : Tag(N->getTag()), Name(N->getRawName()), SizeInBits(N->getSizeInBits()), - AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()), Flags(N->getFlags()) {} + AlignInBits(N->getAlignInBits()), Encoding(N->getEncoding()), + Flags(N->getFlags()) {} bool isKeyOf(const DIBasicType *RHS) const { return Tag == RHS->getTag() && Name == RHS->getRawName() && SizeInBits == RHS->getSizeInBits() && AlignInBits == RHS->getAlignInBits() && - Encoding == RHS->getEncoding() && - Flags == RHS->getFlags(); + Encoding == RHS->getEncoding() && Flags == RHS->getFlags(); } unsigned getHashValue() const { @@ -442,7 +442,7 @@ : Tag(Tag), Name(Name), StringLength(StringLength), StringLengthExp(StringLengthExp), SizeInBits(SizeInBits), AlignInBits(AlignInBits), Encoding(Encoding) {} - MDNodeKeyImpl(const DIStringType *N) + explicit MDNodeKeyImpl(const DIStringType *N) : Tag(N->getTag()), Name(N->getRawName()), StringLength(N->getRawStringLength()), StringLengthExp(N->getRawStringLengthExp()), @@ -482,7 +482,7 @@ BaseType(BaseType), SizeInBits(SizeInBits), OffsetInBits(OffsetInBits), AlignInBits(AlignInBits), DWARFAddressSpace(DWARFAddressSpace), Flags(Flags), ExtraData(ExtraData), Annotations(Annotations) {} - MDNodeKeyImpl(const DIDerivedType *N) + explicit MDNodeKeyImpl(const DIDerivedType *N) : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()), Scope(N->getRawScope()), BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()), @@ -588,7 +588,7 @@ Discriminator(Discriminator), DataLocation(DataLocation), Associated(Associated), Allocated(Allocated), Rank(Rank), Annotations(Annotations) {} - MDNodeKeyImpl(const DICompositeType *N) + explicit MDNodeKeyImpl(const DICompositeType *N) : Tag(N->getTag()), Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()), Scope(N->getRawScope()), BaseType(N->getRawBaseType()), SizeInBits(N->getSizeInBits()), @@ -638,7 +638,7 @@ MDNodeKeyImpl(unsigned Flags, uint8_t CC, Metadata *TypeArray) : Flags(Flags), CC(CC), TypeArray(TypeArray) {} - MDNodeKeyImpl(const DISubroutineType *N) + explicit MDNodeKeyImpl(const DISubroutineType *N) : Flags(N->getFlags()), CC(N->getCC()), TypeArray(N->getRawTypeArray()) {} bool isKeyOf(const DISubroutineType *RHS) const { @@ -660,7 +660,7 @@ Optional Source) : Filename(Filename), Directory(Directory), Checksum(Checksum), Source(Source) {} - MDNodeKeyImpl(const DIFile *N) + explicit MDNodeKeyImpl(const DIFile *N) : Filename(N->getRawFilename()), Directory(N->getRawDirectory()), Checksum(N->getRawChecksum()), Source(N->getRawSource()) {} @@ -712,7 +712,7 @@ Unit(Unit), TemplateParams(TemplateParams), Declaration(Declaration), RetainedNodes(RetainedNodes), ThrownTypes(ThrownTypes), Annotations(Annotations) {} - MDNodeKeyImpl(const DISubprogram *N) + explicit MDNodeKeyImpl(const DISubprogram *N) : Scope(N->getRawScope()), Name(N->getRawName()), LinkageName(N->getRawLinkageName()), File(N->getRawFile()), Line(N->getLine()), Type(N->getRawType()), ScopeLine(N->getScopeLine()), @@ -723,8 +723,8 @@ TemplateParams(N->getRawTemplateParams()), Declaration(N->getRawDeclaration()), RetainedNodes(N->getRawRetainedNodes()), - ThrownTypes(N->getRawThrownTypes()), Annotations(N->getRawAnnotations()) - {} + ThrownTypes(N->getRawThrownTypes()), + Annotations(N->getRawAnnotations()) {} bool isKeyOf(const DISubprogram *RHS) const { return Scope == RHS->getRawScope() && Name == RHS->getRawName() && @@ -810,7 +810,7 @@ MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Line, unsigned Column) : Scope(Scope), File(File), Line(Line), Column(Column) {} - MDNodeKeyImpl(const DILexicalBlock *N) + explicit MDNodeKeyImpl(const DILexicalBlock *N) : Scope(N->getRawScope()), File(N->getRawFile()), Line(N->getLine()), Column(N->getColumn()) {} @@ -831,7 +831,7 @@ MDNodeKeyImpl(Metadata *Scope, Metadata *File, unsigned Discriminator) : Scope(Scope), File(File), Discriminator(Discriminator) {} - MDNodeKeyImpl(const DILexicalBlockFile *N) + explicit MDNodeKeyImpl(const DILexicalBlockFile *N) : Scope(N->getRawScope()), File(N->getRawFile()), Discriminator(N->getDiscriminator()) {} @@ -852,7 +852,7 @@ MDNodeKeyImpl(Metadata *Scope, MDString *Name, bool ExportSymbols) : Scope(Scope), Name(Name), ExportSymbols(ExportSymbols) {} - MDNodeKeyImpl(const DINamespace *N) + explicit MDNodeKeyImpl(const DINamespace *N) : Scope(N->getRawScope()), Name(N->getRawName()), ExportSymbols(N->getExportSymbols()) {} @@ -876,7 +876,7 @@ MDNodeKeyImpl(Metadata *Scope, Metadata *Decl, MDString *Name, Metadata *File, unsigned LineNo) : Scope(Scope), Decl(Decl), Name(Name), File(File), LineNo(LineNo) {} - MDNodeKeyImpl(const DICommonBlock *N) + explicit MDNodeKeyImpl(const DICommonBlock *N) : Scope(N->getRawScope()), Decl(N->getRawDecl()), Name(N->getRawName()), File(N->getRawFile()), LineNo(N->getLineNo()) {} @@ -907,7 +907,7 @@ : File(File), Scope(Scope), Name(Name), ConfigurationMacros(ConfigurationMacros), IncludePath(IncludePath), APINotesFile(APINotesFile), LineNo(LineNo), IsDecl(IsDecl) {} - MDNodeKeyImpl(const DIModule *N) + explicit MDNodeKeyImpl(const DIModule *N) : File(N->getRawFile()), Scope(N->getRawScope()), Name(N->getRawName()), ConfigurationMacros(N->getRawConfigurationMacros()), IncludePath(N->getRawIncludePath()), @@ -935,7 +935,7 @@ MDNodeKeyImpl(MDString *Name, Metadata *Type, bool IsDefault) : Name(Name), Type(Type), IsDefault(IsDefault) {} - MDNodeKeyImpl(const DITemplateTypeParameter *N) + explicit MDNodeKeyImpl(const DITemplateTypeParameter *N) : Name(N->getRawName()), Type(N->getRawType()), IsDefault(N->isDefault()) {} @@ -957,7 +957,7 @@ MDNodeKeyImpl(unsigned Tag, MDString *Name, Metadata *Type, bool IsDefault, Metadata *Value) : Tag(Tag), Name(Name), Type(Type), IsDefault(IsDefault), Value(Value) {} - MDNodeKeyImpl(const DITemplateValueParameter *N) + explicit MDNodeKeyImpl(const DITemplateValueParameter *N) : Tag(N->getTag()), Name(N->getRawName()), Type(N->getRawType()), IsDefault(N->isDefault()), Value(N->getValue()) {} @@ -997,7 +997,7 @@ StaticDataMemberDeclaration(StaticDataMemberDeclaration), TemplateParams(TemplateParams), AlignInBits(AlignInBits), Annotations(Annotations) {} - MDNodeKeyImpl(const DIGlobalVariable *N) + explicit MDNodeKeyImpl(const DIGlobalVariable *N) : Scope(N->getRawScope()), Name(N->getRawName()), LinkageName(N->getRawLinkageName()), File(N->getRawFile()), Line(N->getLine()), Type(N->getRawType()), @@ -1049,7 +1049,7 @@ uint32_t AlignInBits, Metadata *Annotations) : Scope(Scope), Name(Name), File(File), Line(Line), Type(Type), Arg(Arg), Flags(Flags), AlignInBits(AlignInBits), Annotations(Annotations) {} - MDNodeKeyImpl(const DILocalVariable *N) + explicit MDNodeKeyImpl(const DILocalVariable *N) : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()), Type(N->getRawType()), Arg(N->getArg()), Flags(N->getFlags()), AlignInBits(N->getAlignInBits()), @@ -1083,7 +1083,7 @@ MDNodeKeyImpl(Metadata *Scope, MDString *Name, Metadata *File, unsigned Line) : Scope(Scope), Name(Name), File(File), Line(Line) {} - MDNodeKeyImpl(const DILabel *N) + explicit MDNodeKeyImpl(const DILabel *N) : Scope(N->getRawScope()), Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()) {} @@ -1101,8 +1101,8 @@ template <> struct MDNodeKeyImpl { ArrayRef Elements; - MDNodeKeyImpl(ArrayRef Elements) : Elements(Elements) {} - MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {} + explicit MDNodeKeyImpl(ArrayRef Elements) : Elements(Elements) {} + explicit MDNodeKeyImpl(const DIExpression *N) : Elements(N->getElements()) {} bool isKeyOf(const DIExpression *RHS) const { return Elements == RHS->getElements(); @@ -1119,7 +1119,7 @@ MDNodeKeyImpl(Metadata *Variable, Metadata *Expression) : Variable(Variable), Expression(Expression) {} - MDNodeKeyImpl(const DIGlobalVariableExpression *N) + explicit MDNodeKeyImpl(const DIGlobalVariableExpression *N) : Variable(N->getRawVariable()), Expression(N->getRawExpression()) {} bool isKeyOf(const DIGlobalVariableExpression *RHS) const { @@ -1144,7 +1144,7 @@ Metadata *Type) : Name(Name), File(File), Line(Line), GetterName(GetterName), SetterName(SetterName), Attributes(Attributes), Type(Type) {} - MDNodeKeyImpl(const DIObjCProperty *N) + explicit MDNodeKeyImpl(const DIObjCProperty *N) : Name(N->getRawName()), File(N->getRawFile()), Line(N->getLine()), GetterName(N->getRawGetterName()), SetterName(N->getRawSetterName()), Attributes(N->getAttributes()), Type(N->getRawType()) {} @@ -1175,7 +1175,7 @@ unsigned Line, MDString *Name, Metadata *Elements) : Tag(Tag), Scope(Scope), Entity(Entity), File(File), Line(Line), Name(Name), Elements(Elements) {} - MDNodeKeyImpl(const DIImportedEntity *N) + explicit MDNodeKeyImpl(const DIImportedEntity *N) : Tag(N->getTag()), Scope(N->getRawScope()), Entity(N->getRawEntity()), File(N->getRawFile()), Line(N->getLine()), Name(N->getRawName()), Elements(N->getRawElements()) {} @@ -1200,7 +1200,7 @@ MDNodeKeyImpl(unsigned MIType, unsigned Line, MDString *Name, MDString *Value) : MIType(MIType), Line(Line), Name(Name), Value(Value) {} - MDNodeKeyImpl(const DIMacro *N) + explicit MDNodeKeyImpl(const DIMacro *N) : MIType(N->getMacinfoType()), Line(N->getLine()), Name(N->getRawName()), Value(N->getRawValue()) {} @@ -1223,7 +1223,7 @@ MDNodeKeyImpl(unsigned MIType, unsigned Line, Metadata *File, Metadata *Elements) : MIType(MIType), Line(Line), File(File), Elements(Elements) {} - MDNodeKeyImpl(const DIMacroFile *N) + explicit MDNodeKeyImpl(const DIMacroFile *N) : MIType(N->getMacinfoType()), Line(N->getLine()), File(N->getRawFile()), Elements(N->getRawElements()) {} @@ -1240,8 +1240,8 @@ template <> struct MDNodeKeyImpl { ArrayRef Args; - MDNodeKeyImpl(ArrayRef Args) : Args(Args) {} - MDNodeKeyImpl(const DIArgList *N) : Args(N->getArgs()) {} + explicit MDNodeKeyImpl(ArrayRef Args) : Args(Args) {} + explicit MDNodeKeyImpl(const DIArgList *N) : Args(N->getArgs()) {} bool isKeyOf(const DIArgList *RHS) const { return Args == RHS->getArgs(); } @@ -1526,7 +1526,7 @@ /// not. bool DiscardValueNames = false; - LLVMContextImpl(LLVMContext &C); + explicit LLVMContextImpl(LLVMContext &C); ~LLVMContextImpl(); /// Destroy the ConstantArrays if they are not used. Index: llvm/lib/IR/LegacyPassManager.cpp =================================================================== --- llvm/lib/IR/LegacyPassManager.cpp +++ llvm/lib/IR/LegacyPassManager.cpp @@ -63,7 +63,7 @@ /// isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions /// or higher is specified. -bool PMDataManager::isPassDebuggingExecutionsOrMore() const { +bool PMDataManager::isPassDebuggingExecutionsOrMore() { return PassDebugging >= Executions; } @@ -336,8 +336,8 @@ bool FunctionPassManagerImpl::doFinalization(Module &M) { bool Changed = false; - for (int Index = getNumContainedManagers() - 1; Index >= 0; --Index) - Changed |= getContainedManager(Index)->doFinalization(M); + for (unsigned Index = getNumContainedManagers(); Index > 0; --Index) + Changed |= getContainedManager(Index - 1)->doFinalization(M); for (ImmutablePass *ImPass : getImmutablePasses()) Changed |= ImPass->doFinalization(M); @@ -1013,10 +1013,10 @@ // Remove all interfaces this pass implements, for which it is also // listed as the available implementation. - const std::vector &II = PInf->getInterfacesImplemented(); - for (unsigned i = 0, e = II.size(); i != e; ++i) { - DenseMap::iterator Pos = - AvailableAnalysis.find(II[i]->getTypeInfo()); + const std::vector &II = PInf->getInterfacesImplemented(); + for (auto *I : II) { + DenseMap::iterator Pos = + AvailableAnalysis.find(I->getTypeInfo()); if (Pos != AvailableAnalysis.end() && Pos->second == P) AvailableAnalysis.erase(Pos); } @@ -1499,8 +1499,8 @@ bool FPPassManager::doFinalization(Module &M) { bool Changed = false; - for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index) - Changed |= getContainedPass(Index)->doFinalization(M); + for (unsigned Index = getNumContainedPasses(); Index > 0; --Index) + Changed |= getContainedPass(Index - 1)->doFinalization(M); return Changed; } @@ -1586,8 +1586,8 @@ } // Finalize module passes - for (int Index = getNumContainedPasses() - 1; Index >= 0; --Index) - Changed |= getContainedPass(Index)->doFinalization(M); + for (unsigned Index = getNumContainedPasses(); Index > 0; --Index) + Changed |= getContainedPass(Index - 1)->doFinalization(M); // Finalize on-the-fly passes for (auto &OnTheFlyManager : OnTheFlyManagers) { @@ -1772,4 +1772,4 @@ PM->add(this); } -legacy::PassManagerBase::~PassManagerBase() {} +legacy::PassManagerBase::~PassManagerBase() = default; Index: llvm/lib/IR/Metadata.cpp =================================================================== --- llvm/lib/IR/Metadata.cpp +++ llvm/lib/IR/Metadata.cpp @@ -1032,10 +1032,10 @@ // First, walk both lists in order of the lower boundary of each interval. // At each step, try to merge the new interval to the last one we adedd. SmallVector EndPoints; - int AI = 0; - int BI = 0; - int AN = A->getNumOperands() / 2; - int BN = B->getNumOperands() / 2; + unsigned AI = 0; + unsigned BI = 0; + unsigned AN = A->getNumOperands() / 2; + unsigned BN = B->getNumOperands() / 2; while (AI < AN && BI < BN) { ConstantInt *ALow = mdconst::extract(A->getOperand(2 * AI)); ConstantInt *BLow = mdconst::extract(B->getOperand(2 * BI)); @@ -1063,12 +1063,12 @@ // If we have more than 2 ranges (4 endpoints) we have to try to merge // the last and first ones. - unsigned Size = EndPoints.size(); + size_t Size = EndPoints.size(); if (Size > 4) { ConstantInt *FB = EndPoints[0]; ConstantInt *FE = EndPoints[1]; if (tryMergeRange(EndPoints, FB, FE)) { - for (unsigned i = 0; i < Size - 2; ++i) { + for (size_t i = 0; i < Size - 2; ++i) { EndPoints[i] = EndPoints[i + 2]; } EndPoints.resize(Size - 2); Index: llvm/lib/IR/ModuleSummaryIndex.cpp =================================================================== --- llvm/lib/IR/ModuleSummaryIndex.cpp +++ llvm/lib/IR/ModuleSummaryIndex.cpp @@ -56,8 +56,8 @@ // With DSOLocal propagation done, the flag in evey summary is the same. // Check the first one is enough. return WithDSOLocalPropagation - ? getSummaryList().size() && getSummaryList()[0]->isDSOLocal() - : getSummaryList().size() && + ? !getSummaryList().empty() && getSummaryList()[0]->isDSOLocal() + : !getSummaryList().empty() && llvm::all_of( getSummaryList(), [](const std::unique_ptr &Summary) { @@ -67,7 +67,7 @@ bool ValueInfo::canAutoHide() const { // Can only auto hide if all copies are eligible to auto hide. - return getSummaryList().size() && + return !getSummaryList().empty() && llvm::all_of(getSummaryList(), [](const std::unique_ptr &Summary) { return Summary->canAutoHide(); @@ -80,10 +80,10 @@ // located in the end of the RefEdgeList. auto Refs = refs(); unsigned RORefCnt = 0, WORefCnt = 0; - int I; - for (I = Refs.size() - 1; I >= 0 && Refs[I].isWriteOnly(); --I) + unsigned I; + for (I = Refs.size(); I > 0 && Refs[I - 1].isWriteOnly(); --I) WORefCnt++; - for (; I >= 0 && Refs[I].isReadOnly(); --I) + for (; I > 0 && Refs[I - 1].isReadOnly(); --I) RORefCnt++; return {RORefCnt, WORefCnt}; } @@ -300,7 +300,7 @@ setWithDSOLocalPropagation(); if (llvm::AreStatisticsEnabled()) for (auto &P : *this) - if (P.second.SummaryList.size()) + if (!P.second.SummaryList.empty()) if (auto *GVS = dyn_cast( P.second.SummaryList[0]->getBaseObject())) if (isGlobalValueLive(GVS)) { @@ -329,7 +329,7 @@ // However we do not promote objects referenced by writeonly GV // initializer by means of converting it to 'zeroinitializer' return !(ImportConstantsWithRefs && GVS->isConstant()) && - !isReadOnly(GVS) && !isWriteOnly(GVS) && GVS->refs().size(); + !isReadOnly(GVS) && !isWriteOnly(GVS) && !GVS->refs().empty(); }; auto *GVS = cast(S->getBaseObject()); Index: llvm/lib/IR/Operator.cpp =================================================================== --- llvm/lib/IR/Operator.cpp +++ llvm/lib/IR/Operator.cpp @@ -38,7 +38,7 @@ Align Result = Align(llvm::Value::MaximumAlignment); for (gep_type_iterator GTI = gep_type_begin(this), GTE = gep_type_end(this); GTI != GTE; ++GTI) { - int64_t Offset = 1; + uint64_t Offset; ConstantInt *OpC = dyn_cast(GTI.getOperand()); if (StructType *STy = GTI.getStructTypeOrNull()) { @@ -48,9 +48,7 @@ assert(GTI.isSequential() && "should be sequencial"); /// If the index isn't know we take 1 because it is the index that will /// give the worse alignment of the offset. - int64_t ElemCount = 1; - if (OpC) - ElemCount = OpC->getZExtValue(); + const uint64_t ElemCount = OpC ? OpC->getZExtValue() : 1; Offset = DL.getTypeAllocSize(GTI.getIndexedType()) * ElemCount; } Result = Align(MinAlign(Offset, Result.value())); Index: llvm/lib/IR/OptBisect.cpp =================================================================== --- llvm/lib/IR/OptBisect.cpp +++ llvm/lib/IR/OptBisect.cpp @@ -21,13 +21,6 @@ using namespace llvm; -static cl::opt OptBisectLimit("opt-bisect-limit", cl::Hidden, - cl::init(OptBisect::Disabled), cl::Optional, - cl::cb([](int Limit) { - llvm::OptBisector->setLimit(Limit); - }), - cl::desc("Maximum optimization to perform")); - static void printPassMessage(const StringRef &Name, int PassNum, StringRef TargetDesc, bool Running) { StringRef Status = Running ? "" : "NOT "; @@ -45,9 +38,9 @@ const StringRef TargetDesc) { assert(isEnabled()); - int CurBisectNum = ++LastBisectNum; - bool ShouldRun = (BisectLimit == -1 || CurBisectNum <= BisectLimit); - printPassMessage(PassName, CurBisectNum, TargetDesc, ShouldRun); + LastBisectNum++; + bool ShouldRun = (BisectLimit == -1 || LastBisectNum <= BisectLimit); + printPassMessage(PassName, LastBisectNum, TargetDesc, ShouldRun); return ShouldRun; } Index: llvm/lib/IR/Pass.cpp =================================================================== --- llvm/lib/IR/Pass.cpp +++ llvm/lib/IR/Pass.cpp @@ -232,7 +232,7 @@ VectorType &CFGOnlyList; - GetCFGOnlyPasses(VectorType &L) : CFGOnlyList(L) {} + explicit GetCFGOnlyPasses(VectorType &L) : CFGOnlyList(L) {} void passEnumerate(const PassInfo *P) override { if (P->isCFGOnlyPass()) Index: llvm/lib/IR/PassTimingInfo.cpp =================================================================== --- llvm/lib/IR/PassTimingInfo.cpp +++ llvm/lib/IR/PassTimingInfo.cpp @@ -62,7 +62,8 @@ private: StringMap PassIDCountMap; ///< Map that counts instances of passes - DenseMap> TimingData; ///< timers for pass instances + DenseMap> + TimingData; ///< timers for pass instances TimerGroup TG; public: @@ -141,7 +142,8 @@ StringRef PassArgument; if (const PassInfo *PI = Pass::lookupPassInfo(P->getPassID())) PassArgument = PI->getPassArgument(); - T.reset(newPassTimer(PassArgument.empty() ? PassName : PassArgument, PassName)); + T.reset( + newPassTimer(PassArgument.empty() ? PassName : PassArgument, PassName)); } return T.get(); } @@ -173,7 +175,7 @@ Timer &TimePassesHandler::getPassTimer(StringRef PassID) { if (!PerRun) { TimerVector &Timers = TimingData[PassID]; - if (Timers.size() == 0) + if (Timers.empty()) Timers.emplace_back(new Timer(PassID, PassID, TG)); return *Timers.front(); } @@ -199,9 +201,7 @@ TimePassesHandler::TimePassesHandler() : TimePassesHandler(TimePassesIsEnabled, TimePassesPerRun) {} -void TimePassesHandler::setOutStream(raw_ostream &Out) { - OutStream = &Out; -} +void TimePassesHandler::setOutStream(raw_ostream &Out) { OutStream = &Out; } void TimePassesHandler::print() { if (!Enabled) @@ -214,21 +214,23 @@ << ":\n\tRunning:\n"; for (auto &I : TimingData) { StringRef PassID = I.getKey(); - const TimerVector& MyTimers = I.getValue(); + const TimerVector &MyTimers = I.getValue(); for (unsigned idx = 0; idx < MyTimers.size(); idx++) { - const Timer* MyTimer = MyTimers[idx].get(); + const Timer *MyTimer = MyTimers[idx].get(); if (MyTimer && MyTimer->isRunning()) - dbgs() << "\tTimer " << MyTimer << " for pass " << PassID << "(" << idx << ")\n"; + dbgs() << "\tTimer " << MyTimer << " for pass " << PassID << "(" << idx + << ")\n"; } } dbgs() << "\tTriggered:\n"; for (auto &I : TimingData) { StringRef PassID = I.getKey(); - const TimerVector& MyTimers = I.getValue(); + const TimerVector &MyTimers = I.getValue(); for (unsigned idx = 0; idx < MyTimers.size(); idx++) { - const Timer* MyTimer = MyTimers[idx].get(); + const Timer *MyTimer = MyTimers[idx].get(); if (MyTimer && MyTimer->hasTriggered() && !MyTimer->isRunning()) - dbgs() << "\tTimer " << MyTimer << " for pass " << PassID << "(" << idx << ")\n"; + dbgs() << "\tTimer " << MyTimer << " for pass " << PassID << "(" << idx + << ")\n"; } } } @@ -241,7 +243,7 @@ } void TimePassesHandler::stopTimer(StringRef PassID) { - assert(TimerStack.size() > 0 && "empty stack in popTimer"); + assert(!TimerStack.empty() && "empty stack in popTimer"); Timer *MyTimer = TimerStack.pop_back_val(); assert(MyTimer && "timer should be present"); if (MyTimer->isRunning()) @@ -275,9 +277,9 @@ return; PIC.registerBeforeNonSkippedPassCallback( - [this](StringRef P, Any) { this->runBeforePass(P); }); + [this](StringRef P, const Any &) { this->runBeforePass(P); }); PIC.registerAfterPassCallback( - [this](StringRef P, Any, const PreservedAnalyses &) { + [this](StringRef P, const Any &, const PreservedAnalyses &) { this->runAfterPass(P); }); PIC.registerAfterPassInvalidatedCallback( @@ -285,9 +287,9 @@ this->runAfterPass(P); }); PIC.registerBeforeAnalysisCallback( - [this](StringRef P, Any) { this->runBeforePass(P); }); + [this](StringRef P, const Any &) { this->runBeforePass(P); }); PIC.registerAfterAnalysisCallback( - [this](StringRef P, Any) { this->runAfterPass(P); }); + [this](StringRef P, const Any &) { this->runAfterPass(P); }); } } // namespace llvm Index: llvm/lib/IR/PseudoProbe.cpp =================================================================== --- llvm/lib/IR/PseudoProbe.cpp +++ llvm/lib/IR/PseudoProbe.cpp @@ -29,7 +29,7 @@ const DILocation *DIL = DLoc; auto Discriminator = DIL->getDiscriminator(); if (DILocation::isPseudoProbeDiscriminator(Discriminator)) { - PseudoProbe Probe; + PseudoProbe Probe{}; Probe.Id = PseudoProbeDwarfDiscriminator::extractProbeIndex(Discriminator); Probe.Type = @@ -47,7 +47,7 @@ Optional extractProbe(const Instruction &Inst) { if (const auto *II = dyn_cast(&Inst)) { - PseudoProbe Probe; + PseudoProbe Probe{}; Probe.Id = II->getIndex()->getZExtValue(); Probe.Type = (uint32_t)PseudoProbeType::Block; Probe.Attr = II->getAttributes()->getZExtValue(); Index: llvm/lib/IR/Verifier.cpp =================================================================== --- llvm/lib/IR/Verifier.cpp +++ llvm/lib/IR/Verifier.cpp @@ -3313,7 +3313,7 @@ return PL->getAddressSpace() == PR->getAddressSpace(); } -static AttrBuilder getParameterABIAttributes(int I, AttributeList Attrs) { +static AttrBuilder getParameterABIAttributes(unsigned I, AttributeList Attrs) { static const Attribute::AttrKind ABIAttrs[] = { Attribute::StructRet, Attribute::ByVal, Attribute::InAlloca, Attribute::InReg, Attribute::StackAlignment, Attribute::SwiftSelf, @@ -3381,12 +3381,12 @@ // - Only sret, byval, swiftself, and swiftasync ABI-impacting attributes // are allowed in swifttailcc call - for (int I = 0, E = CallerTy->getNumParams(); I != E; ++I) { + for (unsigned I = 0, E = CallerTy->getNumParams(); I != E; ++I) { AttrBuilder ABIAttrs = getParameterABIAttributes(I, CallerAttrs); SmallString<32> Context{CCName, StringRef(" musttail caller")}; verifyTailCCMustTailAttrs(ABIAttrs, Context); } - for (int I = 0, E = CalleeTy->getNumParams(); I != E; ++I) { + for (unsigned I = 0, E = CalleeTy->getNumParams(); I != E; ++I) { AttrBuilder ABIAttrs = getParameterABIAttributes(I, CalleeAttrs); SmallString<32> Context{CCName, StringRef(" musttail callee")}; verifyTailCCMustTailAttrs(ABIAttrs, Context); @@ -3404,7 +3404,7 @@ Assert(CallerTy->getNumParams() == CalleeTy->getNumParams(), "cannot guarantee tail call due to mismatched parameter counts", &CI); - for (int I = 0, E = CallerTy->getNumParams(); I != E; ++I) { + for (unsigned I = 0, E = CallerTy->getNumParams(); I != E; ++I) { Assert( isTypeCongruent(CallerTy->getParamType(I), CalleeTy->getParamType(I)), "cannot guarantee tail call due to mismatched parameter types", &CI); @@ -3413,7 +3413,7 @@ // - All ABI-impacting function attributes, such as sret, byval, inreg, // returned, preallocated, and inalloca, must match. - for (int I = 0, E = CallerTy->getNumParams(); I != E; ++I) { + for (unsigned I = 0, E = CallerTy->getNumParams(); I != E; ++I) { AttrBuilder CallerABIAttrs = getParameterABIAttributes(I, CallerAttrs); AttrBuilder CalleeABIAttrs = getParameterABIAttributes(I, CalleeAttrs); Assert(CallerABIAttrs == CalleeABIAttrs, @@ -5599,15 +5599,6 @@ if (!Fragment) return; - // The frontend helps out GDB by emitting the members of local anonymous - // unions as artificial local variables with shared storage. When SROA splits - // the storage for artificial local variables that are smaller than the entire - // union, the overhang piece will be outside of the allotted space for the - // variable and this check fails. - // FIXME: Remove this check as soon as clang stops doing this; it hides bugs. - if (V->isArtificial()) - return; - verifyFragmentExpression(*V, *Fragment, &I); } @@ -6246,7 +6237,7 @@ AnalysisKey VerifierAnalysis::Key; VerifierAnalysis::Result VerifierAnalysis::run(Module &M, ModuleAnalysisManager &) { - Result Res; + Result Res{}; Res.IRBroken = llvm::verifyModule(M, &dbgs(), &Res.DebugInfoBroken); return Res; } Index: llvm/lib/Support/APInt.cpp =================================================================== --- llvm/lib/Support/APInt.cpp +++ llvm/lib/Support/APInt.cpp @@ -834,7 +834,7 @@ } // Determine if the value is negative. - bool isNeg = isSigned ? (*this)[BitWidth-1] : false; + bool isNeg = isSigned && (*this)[BitWidth - 1]; // Construct the absolute value if we're negative. APInt Tmp(isNeg ? -(*this) : (*this)); Index: llvm/tools/llvm-c-test/echo.cpp =================================================================== --- llvm/tools/llvm-c-test/echo.cpp +++ llvm/tools/llvm-c-test/echo.cpp @@ -492,8 +492,7 @@ LLVMOpcode Op = LLVMGetInstructionOpcode(Src); switch(Op) { case LLVMRet: { - int OpCount = LLVMGetNumOperands(Src); - if (OpCount == 0) + if (LLVMGetNumOperands(Src) == 0) Dst = LLVMBuildRetVoid(Builder); else Dst = LLVMBuildRet(Builder, CloneValue(LLVMGetOperand(Src, 0)));