From 259294aa922bdf7254f08bc2f7a8f848ba52d2a1 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Sat, 2 Jul 2016 11:41:41 +0000 Subject: [PATCH] Use arrays or initializer lists to feed ArrayRefs instead of SmallVector where possible. No functionality change intended git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@274432 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Sema/AttributeList.h | 9 +- lib/CodeGen/CGCUDANV.cpp | 5 +- lib/CodeGen/CGObjCGNU.cpp | 89 +++++++------------ lib/CodeGen/CGObjCMac.cpp | 22 +++-- lib/CodeGen/TargetInfo.cpp | 5 +- lib/Frontend/TestModuleFileExtension.cpp | 4 +- .../Frontend/AnalysisConsumer.cpp | 5 +- 7 files changed, 53 insertions(+), 86 deletions(-) diff --git a/include/clang/Sema/AttributeList.h b/include/clang/Sema/AttributeList.h index e92f7f2951..38e5e94390 100644 --- a/include/clang/Sema/AttributeList.h +++ b/include/clang/Sema/AttributeList.h @@ -283,11 +283,10 @@ private: Invalid(false), UsedAsTypeAttr(false), IsAvailability(false), IsTypeTagForDatatype(false), IsProperty(false), HasParsedType(false), HasProcessingCache(false), NextInPosition(nullptr), NextInPool(nullptr) { - ArgsVector Args; - Args.push_back(Parm1); - Args.push_back(Parm2); - Args.push_back(Parm3); - memcpy(getArgsBuffer(), &Args[0], 3 * sizeof(ArgsUnion)); + ArgsUnion *Args = getArgsBuffer(); + Args[0] = Parm1; + Args[1] = Parm2; + Args[2] = Parm3; AttrKind = getKind(getName(), getScopeName(), syntaxUsed); } diff --git a/lib/CodeGen/CGCUDANV.cpp b/lib/CodeGen/CGCUDANV.cpp index c6788091ca..ce8b3c3428 100644 --- a/lib/CodeGen/CGCUDANV.cpp +++ b/lib/CodeGen/CGCUDANV.cpp @@ -98,10 +98,7 @@ CGNVCUDARuntime::CGNVCUDARuntime(CodeGenModule &CGM) llvm::Constant *CGNVCUDARuntime::getSetupArgumentFn() const { // cudaError_t cudaSetupArgument(void *, size_t, size_t) - std::vector Params; - Params.push_back(VoidPtrTy); - Params.push_back(SizeTy); - Params.push_back(SizeTy); + llvm::Type *Params[] = {VoidPtrTy, SizeTy, SizeTy}; return CGM.CreateRuntimeFunction(llvm::FunctionType::get(IntTy, Params, false), "cudaSetupArgument"); diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp index f9f48c8a47..a24c212e60 100644 --- a/lib/CodeGen/CGObjCGNU.cpp +++ b/lib/CodeGen/CGObjCGNU.cpp @@ -1528,21 +1528,17 @@ GenerateMethodList(StringRef ClassName, IMPTy, //Method pointer nullptr); std::vector Methods; - std::vector Elements; for (unsigned int i = 0, e = MethodTypes.size(); i < e; ++i) { - Elements.clear(); llvm::Constant *Method = TheModule.getFunction(SymbolNameForMethod(ClassName, CategoryName, MethodSels[i], isClassMethodList)); assert(Method && "Can't generate metadata for method that doesn't exist"); llvm::Constant *C = MakeConstantString(MethodSels[i].getAsString()); - Elements.push_back(C); - Elements.push_back(MethodTypes[i]); Method = llvm::ConstantExpr::getBitCast(Method, IMPTy); - Elements.push_back(Method); - Methods.push_back(llvm::ConstantStruct::get(ObjCMethodTy, Elements)); + Methods.push_back( + llvm::ConstantStruct::get(ObjCMethodTy, {C, MethodTypes[i], Method})); } // Array of method structures @@ -1585,23 +1581,18 @@ GenerateIvarList(ArrayRef IvarNames, IntTy, nullptr); std::vector Ivars; - std::vector Elements; for (unsigned int i = 0, e = IvarNames.size() ; i < e ; i++) { - Elements.clear(); - Elements.push_back(IvarNames[i]); - Elements.push_back(IvarTypes[i]); - Elements.push_back(IvarOffsets[i]); - Ivars.push_back(llvm::ConstantStruct::get(ObjCIvarTy, Elements)); + Ivars.push_back(llvm::ConstantStruct::get( + ObjCIvarTy, {IvarNames[i], IvarTypes[i], IvarOffsets[i]})); } // Array of method structures llvm::ArrayType *ObjCIvarArrayTy = llvm::ArrayType::get(ObjCIvarTy, IvarNames.size()); - - Elements.clear(); - Elements.push_back(llvm::ConstantInt::get(IntTy, (int)IvarNames.size())); - Elements.push_back(llvm::ConstantArray::get(ObjCIvarArrayTy, Ivars)); + llvm::Constant *Elements[] = { + llvm::ConstantInt::get(IntTy, (int)IvarNames.size()), + llvm::ConstantArray::get(ObjCIvarArrayTy, Ivars)}; // Structure containing array and array count llvm::StructType *ObjCIvarListTy = llvm::StructType::get(IntTy, ObjCIvarArrayTy, @@ -1713,12 +1704,9 @@ GenerateProtocolMethodList(ArrayRef MethodNames, PtrToInt8Ty, nullptr); std::vector Methods; - std::vector Elements; for (unsigned int i = 0, e = MethodTypes.size() ; i < e ; i++) { - Elements.clear(); - Elements.push_back(MethodNames[i]); - Elements.push_back(MethodTypes[i]); - Methods.push_back(llvm::ConstantStruct::get(ObjCMethodDescTy, Elements)); + Methods.push_back(llvm::ConstantStruct::get( + ObjCMethodDescTy, {MethodNames[i], MethodTypes[i]})); } llvm::ArrayType *ObjCMethodArrayTy = llvm::ArrayType::get(ObjCMethodDescTy, MethodNames.size()); @@ -1793,17 +1781,13 @@ llvm::Constant *CGObjCGNU::GenerateEmptyProtocol( MethodList->getType(), MethodList->getType(), nullptr); - std::vector Elements; // The isa pointer must be set to a magic number so the runtime knows it's // the correct layout. - Elements.push_back(llvm::ConstantExpr::getIntToPtr( - llvm::ConstantInt::get(Int32Ty, ProtocolVersion), IdTy)); - Elements.push_back(MakeConstantString(ProtocolName, ".objc_protocol_name")); - Elements.push_back(ProtocolList); - Elements.push_back(MethodList); - Elements.push_back(MethodList); - Elements.push_back(MethodList); - Elements.push_back(MethodList); + llvm::Constant *Elements[] = { + llvm::ConstantExpr::getIntToPtr( + llvm::ConstantInt::get(Int32Ty, ProtocolVersion), IdTy), + MakeConstantString(ProtocolName, ".objc_protocol_name"), ProtocolList, + MethodList, MethodList, MethodList, MethodList}; return MakeGlobal(ProtocolTy, Elements, CGM.getPointerAlign(), ".objc_protocol"); } @@ -1951,19 +1935,14 @@ void CGObjCGNU::GenerateProtocol(const ObjCProtocolDecl *PD) { PropertyList->getType(), OptionalPropertyList->getType(), nullptr); - std::vector Elements; // The isa pointer must be set to a magic number so the runtime knows it's // the correct layout. - Elements.push_back(llvm::ConstantExpr::getIntToPtr( - llvm::ConstantInt::get(Int32Ty, ProtocolVersion), IdTy)); - Elements.push_back(MakeConstantString(ProtocolName, ".objc_protocol_name")); - Elements.push_back(ProtocolList); - Elements.push_back(InstanceMethodList); - Elements.push_back(ClassMethodList); - Elements.push_back(OptionalInstanceMethodList); - Elements.push_back(OptionalClassMethodList); - Elements.push_back(PropertyList); - Elements.push_back(OptionalPropertyList); + llvm::Constant *Elements[] = { + llvm::ConstantExpr::getIntToPtr( + llvm::ConstantInt::get(Int32Ty, ProtocolVersion), IdTy), + MakeConstantString(ProtocolName, ".objc_protocol_name"), ProtocolList, + InstanceMethodList, ClassMethodList, OptionalInstanceMethodList, + OptionalClassMethodList, PropertyList, OptionalPropertyList}; ExistingProtocols[ProtocolName] = llvm::ConstantExpr::getBitCast(MakeGlobal(ProtocolTy, Elements, CGM.getPointerAlign(), ".objc_protocol"), IdTy); @@ -2089,20 +2068,20 @@ void CGObjCGNU::GenerateCategory(const ObjCCategoryImplDecl *OCD) { E = Protos.end(); I != E; ++I) Protocols.push_back((*I)->getNameAsString()); - std::vector Elements; - Elements.push_back(MakeConstantString(CategoryName)); - Elements.push_back(MakeConstantString(ClassName)); - // Instance method list - Elements.push_back(llvm::ConstantExpr::getBitCast(GenerateMethodList( - ClassName, CategoryName, InstanceMethodSels, InstanceMethodTypes, - false), PtrTy)); - // Class method list - Elements.push_back(llvm::ConstantExpr::getBitCast(GenerateMethodList( - ClassName, CategoryName, ClassMethodSels, ClassMethodTypes, true), - PtrTy)); - // Protocol list - Elements.push_back(llvm::ConstantExpr::getBitCast( - GenerateProtocolList(Protocols), PtrTy)); + llvm::Constant *Elements[] = { + MakeConstantString(CategoryName), MakeConstantString(ClassName), + // Instance method list + llvm::ConstantExpr::getBitCast( + GenerateMethodList(ClassName, CategoryName, InstanceMethodSels, + InstanceMethodTypes, false), + PtrTy), + // Class method list + llvm::ConstantExpr::getBitCast(GenerateMethodList(ClassName, CategoryName, + ClassMethodSels, + ClassMethodTypes, true), + PtrTy), + // Protocol list + llvm::ConstantExpr::getBitCast(GenerateProtocolList(Protocols), PtrTy)}; Categories.push_back(llvm::ConstantExpr::getBitCast( MakeGlobal(llvm::StructType::get(PtrToInt8Ty, PtrToInt8Ty, PtrTy, PtrTy, PtrTy, nullptr), Elements, CGM.getPointerAlign()), diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 019cfc601f..a4dc628396 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -236,13 +236,11 @@ public: CodeGen::CodeGenTypes &Types = CGM.getTypes(); ASTContext &Ctx = CGM.getContext(); // id objc_getProperty (id, SEL, ptrdiff_t, bool) - SmallVector Params; CanQualType IdType = Ctx.getCanonicalParamType(Ctx.getObjCIdType()); CanQualType SelType = Ctx.getCanonicalParamType(Ctx.getObjCSelType()); - Params.push_back(IdType); - Params.push_back(SelType); - Params.push_back(Ctx.getPointerDiffType()->getCanonicalTypeUnqualified()); - Params.push_back(Ctx.BoolTy); + CanQualType Params[] = { + IdType, SelType, + Ctx.getPointerDiffType()->getCanonicalTypeUnqualified(), Ctx.BoolTy}; llvm::FunctionType *FTy = Types.GetFunctionType( Types.arrangeBuiltinFunctionDeclaration(IdType, Params)); @@ -253,15 +251,15 @@ public: CodeGen::CodeGenTypes &Types = CGM.getTypes(); ASTContext &Ctx = CGM.getContext(); // void objc_setProperty (id, SEL, ptrdiff_t, id, bool, bool) - SmallVector Params; CanQualType IdType = Ctx.getCanonicalParamType(Ctx.getObjCIdType()); CanQualType SelType = Ctx.getCanonicalParamType(Ctx.getObjCSelType()); - Params.push_back(IdType); - Params.push_back(SelType); - Params.push_back(Ctx.getPointerDiffType()->getCanonicalTypeUnqualified()); - Params.push_back(IdType); - Params.push_back(Ctx.BoolTy); - Params.push_back(Ctx.BoolTy); + CanQualType Params[] = { + IdType, + SelType, + Ctx.getPointerDiffType()->getCanonicalTypeUnqualified(), + IdType, + Ctx.BoolTy, + Ctx.BoolTy}; llvm::FunctionType *FTy = Types.GetFunctionType( Types.arrangeBuiltinFunctionDeclaration(Ctx.VoidTy, Params)); diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp index 28651141b2..aa67e71284 100644 --- a/lib/CodeGen/TargetInfo.cpp +++ b/lib/CodeGen/TargetInfo.cpp @@ -7493,9 +7493,8 @@ void XCoreTargetCodeGenInfo::emitTargetMD(const Decl *D, llvm::GlobalValue *GV, SmallStringEnc Enc; if (getTypeString(Enc, D, CGM, TSC)) { llvm::LLVMContext &Ctx = CGM.getModule().getContext(); - llvm::SmallVector MDVals; - MDVals.push_back(llvm::ConstantAsMetadata::get(GV)); - MDVals.push_back(llvm::MDString::get(Ctx, Enc.str())); + llvm::Metadata *MDVals[] = {llvm::ConstantAsMetadata::get(GV), + llvm::MDString::get(Ctx, Enc.str())}; llvm::NamedMDNode *MD = CGM.getModule().getOrInsertNamedMetadata("xcore.typestrings"); MD->addOperand(llvm::MDNode::get(Ctx, MDVals)); diff --git a/lib/Frontend/TestModuleFileExtension.cpp b/lib/Frontend/TestModuleFileExtension.cpp index d1b20c4a80..b43d45f7ae 100644 --- a/lib/Frontend/TestModuleFileExtension.cpp +++ b/lib/Frontend/TestModuleFileExtension.cpp @@ -38,9 +38,7 @@ void TestModuleFileExtension::Writer::writeExtensionContents( OS << "Hello from " << Ext->BlockName << " v" << Ext->MajorVersion << "." << Ext->MinorVersion; } - SmallVector Record; - Record.push_back(FIRST_EXTENSION_RECORD_ID); - Record.push_back(Message.size()); + uint64_t Record[] = {FIRST_EXTENSION_RECORD_ID, Message.size()}; Stream.EmitRecordWithBlob(Abbrev, Record, Message); } diff --git a/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp index f0b7a7d60c..8ac229fc65 100644 --- a/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp +++ b/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp @@ -798,10 +798,7 @@ UbigraphViz::~UbigraphViz() { std::string Ubiviz; if (auto Path = llvm::sys::findProgramByName("ubiviz")) Ubiviz = *Path; - std::vector args; - args.push_back(Ubiviz.c_str()); - args.push_back(Filename.c_str()); - args.push_back(nullptr); + const char *args[] = {Ubiviz.c_str(), Filename.c_str(), nullptr}; if (llvm::sys::ExecuteAndWait(Ubiviz, &args[0], nullptr, nullptr, 0, 0, &ErrMsg)) { -- 2.40.0