From: Benjamin Kramer Date: Fri, 27 May 2016 13:36:58 +0000 (+0000) Subject: Turn copies into references as suggested by clang-tidy's performance-unnecessary... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9d37176cc4a13a6c3644dcfd99819a000e2ba361;p=clang Turn copies into references as suggested by clang-tidy's performance-unnecessary-copy-initialization. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@270994 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index 855017c7c1..d9349fc409 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -825,7 +825,7 @@ private: // * Variable x is equal to the largest literal. // * Variable x is greater than largest literal. bool AlwaysTrue = true, AlwaysFalse = true; - for (llvm::APSInt Value : Values) { + for (const llvm::APSInt &Value : Values) { TryResult Res1, Res2; Res1 = analyzeLogicOperatorCondition(BO1, Value, L1); Res2 = analyzeLogicOperatorCondition(BO2, Value, L2); diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 1eac1d27ed..39f78c3066 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -6541,7 +6541,7 @@ void gcc::Common::ConstructJob(Compilation &C, const JobAction &JA, } } - const std::string customGCCName = D.getCCCGenericGCCName(); + const std::string &customGCCName = D.getCCCGenericGCCName(); const char *GCCName; if (!customGCCName.empty()) GCCName = customGCCName.c_str(); diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index 74e9fed7f1..a37e1cecae 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -2416,7 +2416,7 @@ std::string CompilerInvocation::getModuleHash() const { // Extend the signature with the module file extensions. const FrontendOptions &frontendOpts = getFrontendOpts(); - for (auto ext : frontendOpts.ModuleFileExtensions) { + for (const auto &ext : frontendOpts.ModuleFileExtensions) { code = ext->hashExtension(code); } diff --git a/lib/Frontend/DependencyFile.cpp b/lib/Frontend/DependencyFile.cpp index 93d4a80346..a9b6128237 100644 --- a/lib/Frontend/DependencyFile.cpp +++ b/lib/Frontend/DependencyFile.cpp @@ -177,7 +177,7 @@ public: SeenMissingHeader(false), IncludeModuleFiles(Opts.IncludeModuleFiles), OutputFormat(Opts.OutputFormat) { - for (auto ExtraDep : Opts.ExtraDeps) { + for (const auto &ExtraDep : Opts.ExtraDeps) { AddFilename(ExtraDep); } } diff --git a/lib/Sema/SemaLookup.cpp b/lib/Sema/SemaLookup.cpp index 2afb13e1db..e761436683 100644 --- a/lib/Sema/SemaLookup.cpp +++ b/lib/Sema/SemaLookup.cpp @@ -4060,8 +4060,8 @@ retry_lookup: void TypoCorrectionConsumer::performQualifiedLookups() { unsigned TypoLen = Typo->getName().size(); - for (auto QR : QualifiedResults) { - for (auto NSI : Namespaces) { + for (const TypoCorrection &QR : QualifiedResults) { + for (const auto &NSI : Namespaces) { DeclContext *Ctx = NSI.DeclCtx; const Type *NSType = NSI.NameSpecifier->getAsType(); diff --git a/utils/TableGen/ClangAttrEmitter.cpp b/utils/TableGen/ClangAttrEmitter.cpp index edb613c092..cb29b21c4a 100644 --- a/utils/TableGen/ClangAttrEmitter.cpp +++ b/utils/TableGen/ClangAttrEmitter.cpp @@ -1449,9 +1449,9 @@ CreateSemanticSpellings(const std::vector &Spellings, unsigned Idx = 0; for (auto I = Spellings.begin(), E = Spellings.end(); I != E; ++I, ++Idx) { const FlattenedSpelling &S = *I; - std::string Variety = S.variety(); - std::string Spelling = S.name(); - std::string Namespace = S.nameSpace(); + const std::string &Variety = S.variety(); + const std::string &Spelling = S.name(); + const std::string &Namespace = S.nameSpace(); std::string EnumName; EnumName += (Variety + "_"); @@ -2298,7 +2298,7 @@ void EmitClangAttrHasAttrImpl(RecordKeeper &Records, raw_ostream &OS) { for (auto *R : Attrs) { std::vector Spellings = GetFlattenedSpellings(*R); for (const auto &SI : Spellings) { - std::string Variety = SI.variety(); + const std::string &Variety = SI.variety(); if (Variety == "GNU") GNU.push_back(R); else if (Variety == "Declspec") @@ -2998,9 +2998,10 @@ void EmitClangAttrParsedAttrKinds(RecordKeeper &Records, raw_ostream &OS) { std::vector Spellings = GetFlattenedSpellings(Attr); for (const auto &S : Spellings) { - std::string RawSpelling = S.name(); + const std::string &RawSpelling = S.name(); std::vector *Matches = nullptr; - std::string Spelling, Variety = S.variety(); + std::string Spelling; + const std::string &Variety = S.variety(); if (Variety == "CXX11") { Matches = &CXX11; Spelling += S.nameSpace();