<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Feb 27, 2015 at 6:03 PM, Richard Trieu <span dir="ltr"><<a href="mailto:rtrieu@google.com" target="_blank">rtrieu@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Results from running the warning on LLVM projects. The actual errors are at the end. In total, this warning was triggered 22 times. The breakdown is:<br>
<br>
7 - for (const Foo &x : Foos), where the range Foos only return a copy. Suggest using the non-reference type so the copy is obvious.<br>
5 - for (const Foo x : Foos), where the range Foos does return a reference, but is copied into x. Suggest using the reference type to prevent a copy from being made.<br>
10 - for (const Bar &x : Foos), where Bar is constructed from Foo. Suggest using the non-reference "const Bar" to indicate a copy is intended to be made, or "const Foo &" to prevent a copy from being made.<br></blockquote><div><br>Cool - want to just go ahead with that data then iterate on more data (eg: google-wide, or other large codebases) for improvements?<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
llvm/lib/Analysis/RegionPass.cpp:197:22: error: loop variable 'BB' is always a copy because the range of type 'llvm::iterator_range<llvm::RegionBase<llvm::RegionTraits<llvm::Function> >::block_iterator_wrapper<false> >' does not return a reference<br>
llvm/lib/Analysis/RegionPass.cpp:197:10: note: use non-reference type 'llvm::BasicBlock *const'<br>
llvm/lib/Analysis/RegionPrinter.cpp:126:22: error: loop variable 'BB' is always a copy because the range of type 'llvm::iterator_range<llvm::RegionBase<llvm::RegionTraits<llvm::Function> >::block_iterator_wrapper<true> >' does not return a reference<br>
llvm/lib/Analysis/RegionPrinter.cpp:126:10: note: use non-reference type 'llvm::BasicBlock *const'<br>
llvm/lib/MC/MCDwarf.cpp:814:19: error: loop variable 'sec' of type 'const std::pair<const llvm::MCSection *, std::pair<llvm::MCSymbol *, llvm::MCSymbol *> >' creates a copy from type 'const std::pair<const llvm::MCSection *, std::pair<llvm::MCSymbol *, llvm::MCSymbol *> >'<br>
llvm/lib/MC/MCDwarf.cpp:814:8: note: use reference type 'const std::pair<const llvm::MCSection *, std::pair<llvm::MCSymbol *, llvm::MCSymbol *> > &' to prevent copying<br>
llvm/lib/Object/COFFObjectFile.cpp:263:31: error: loop variable 'SymbI' has type 'const llvm::object::symbol_iterator &' but is initialized with type 'const llvm::object::SymbolRef' resulting in a copy<br>
llvm/lib/Object/COFFObjectFile.cpp:263:8: note: use non-reference type 'const llvm::object::symbol_iterator' to keep the copy or type 'const llvm::object::SymbolRef &' to prevent copying<br>
llvm/lib/Target/AArch64/AArch64CollectLOH.cpp:331:25: error: loop variable 'Entry' of type 'const llvm::detail::DenseMapPair<unsigned int, unsigned int>' creates a copy from type 'const llvm::detail::DenseMapPair<unsigned int, unsigned int>'<br>
llvm/lib/Target/AArch64/AArch64CollectLOH.cpp:331:14: note: use reference type 'const llvm::detail::DenseMapPair<unsigned int, unsigned int> &' to prevent copying<br>
llvm/lib/Transforms/Scalar/StructurizeCFG.cpp:889:20: error: loop variable 'BB' is always a copy because the range of type 'llvm::iterator_range<llvm::RegionBase<llvm::RegionTraits<llvm::Function> >::block_iterator_wrapper<false> >' does not return a reference<br>
llvm/lib/Transforms/Scalar/StructurizeCFG.cpp:889:8: note: use non-reference type 'llvm::BasicBlock *const'<br>
llvm/tools/clang/lib/AST/MicrosoftMangle.cpp:1614:25: error: loop variable 'Arg' of type 'const clang::QualType' creates a copy from type 'const clang::QualType'<br>
llvm/tools/clang/lib/AST/MicrosoftMangle.cpp:1614:10: note: use reference type 'const clang::QualType &' to prevent copying<br>
llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp:3439:19: error: loop variable 'I' of type 'const llvm::detail::DenseMapPair<const clang::Decl *, bool>' creates a copy from type 'const llvm::detail::DenseMapPair<const clang::Decl *, bool>'<br>
llvm/tools/clang/lib/CodeGen/CodeGenModule.cpp:3439:8: note: use reference type 'const llvm::detail::DenseMapPair<const clang::Decl *, bool> &' to prevent copying<br>
llvm/tools/clang/lib/CodeGen/CoverageMappingGen.cpp:945:22: error: loop variable 'Arg' is always a copy because the range of type 'llvm::iterator_range<clang::ConstExprIterator>' does not return a reference<br>
llvm/tools/clang/lib/CodeGen/CoverageMappingGen.cpp:945:10: note: use non-reference type 'const clang::Expr *const'<br>
llvm/tools/clang/lib/Sema/SemaLookup.cpp:3026:20: error: loop variable 'R' is always a copy because the range of type 'llvm::iterator_range<clang::DeclContext::all_lookups_iterator>' does not return a reference<br>
llvm/tools/clang/lib/Sema/SemaLookup.cpp:3026:8: note: use non-reference type 'const llvm::MutableArrayRef<clang::NamedDecl *>'<br>
llvm/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp:1776:19: error: loop variable 'Base' of type 'const clang::CXXBaseSpecifier' creates a copy from type 'const clang::CXXBaseSpecifier'<br>
llvm/tools/clang/lib/Sema/SemaTemplateInstantiate.cpp:1776:8: note: use reference type 'const clang::CXXBaseSpecifier &' to prevent copying<br>
llvm/tools/clang/tools/extra/clang-rename/USRFindingAction.cpp:49:20: error: loop variable 'CtorDecl' is always a copy because the range of type 'llvm::iterator_range<clang::DeclContext::specific_decl_iterator<clang::CXXConstructorDecl> >' does not return a reference<br>
llvm/tools/clang/tools/extra/clang-rename/USRFindingAction.cpp:49:8: note: use non-reference type 'clang::CXXConstructorDecl *const'<br>
llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp:299:68: error: loop variable 'VFTableEntry' has type 'const std::pair<std::pair<StringRef, uint64_t>, StringRef> &' but is initialized with type 'std::pair<const std::pair<llvm::StringRef, unsigned long>, llvm::StringRef>' resulting in a copy<br>
llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp:299:8: note: use non-reference type 'const std::pair<std::pair<StringRef, uint64_t>, StringRef>' to keep the copy or type 'const std::pair<const std::pair<llvm::StringRef, unsigned long>, llvm::StringRef> &' to prevent copying<br>
llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp:306:58: error: loop variable 'VBTable' has type 'const std::pair<StringRef, ArrayRef<little32_t> > &' but is initialized with type 'std::pair<const llvm::StringRef, llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<int, llvm::support::endianness::little, 1> > >' resulting in a copy<br>
llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp:306:8: note: use non-reference type 'const std::pair<StringRef, ArrayRef<little32_t> >' to keep the copy or type 'const std::pair<const llvm::StringRef, llvm::ArrayRef<llvm::support::detail::packed_endian_specific_integral<int, llvm::support::endianness::little, 1> > > &' to prevent copying<br>
llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp:314:59: error: loop variable 'COLPair' has type 'const std::pair<StringRef, CompleteObjectLocator> &' but is initialized with type 'std::pair<const llvm::StringRef, CompleteObjectLocator>' resulting in a copy<br>
llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp:314:8: note: use non-reference type 'const std::pair<StringRef, CompleteObjectLocator>' to keep the copy or type 'const std::pair<const llvm::StringRef, CompleteObjectLocator> &' to prevent copying<br>
llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp:323:62: error: loop variable 'CHDPair' has type 'const std::pair<StringRef, ClassHierarchyDescriptor> &' but is initialized with type 'std::pair<const llvm::StringRef, ClassHierarchyDescriptor>' resulting in a copy<br>
llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp:323:8: note: use non-reference type 'const std::pair<StringRef, ClassHierarchyDescriptor>' to keep the copy or type 'const std::pair<const llvm::StringRef, ClassHierarchyDescriptor> &' to prevent copying<br>
llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp:331:68: error: loop variable 'BCAEntry' has type 'const std::pair<std::pair<StringRef, uint64_t>, StringRef> &' but is initialized with type 'std::pair<const std::pair<llvm::StringRef, unsigned long>, llvm::StringRef>' resulting in a copy<br>
llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp:331:8: note: use non-reference type 'const std::pair<std::pair<StringRef, uint64_t>, StringRef>' to keep the copy or type 'const std::pair<const std::pair<llvm::StringRef, unsigned long>, llvm::StringRef> &' to prevent copying<br>
llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp:338:57: error: loop variable 'BCDPair' has type 'const std::pair<StringRef, BaseClassDescriptor> &' but is initialized with type 'std::pair<const llvm::StringRef, BaseClassDescriptor>' resulting in a copy<br>
llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp:338:8: note: use non-reference type 'const std::pair<StringRef, BaseClassDescriptor>' to keep the copy or type 'const std::pair<const llvm::StringRef, BaseClassDescriptor> &' to prevent copying<br>
llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp:349:52: error: loop variable 'TDPair' has type 'const std::pair<StringRef, TypeDescriptor> &' but is initialized with type 'std::pair<const llvm::StringRef, TypeDescriptor>' resulting in a copy<br>
llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp:349:8: note: use non-reference type 'const std::pair<StringRef, TypeDescriptor>' to keep the copy or type 'const std::pair<const llvm::StringRef, TypeDescriptor> &' to prevent copying<br>
llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp:359:68: error: loop variable 'VTTPair' has type 'const std::pair<std::pair<StringRef, uint64_t>, StringRef> &' but is initialized with type 'std::pair<const std::pair<llvm::StringRef, unsigned long>, llvm::StringRef>' resulting in a copy<br>
llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp:359:8: note: use non-reference type 'const std::pair<std::pair<StringRef, uint64_t>, StringRef>' to keep the copy or type 'const std::pair<const std::pair<llvm::StringRef, unsigned long>, llvm::StringRef> &' to prevent copying<br>
llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp:366:47: error: loop variable 'TIPair' has type 'const std::pair<StringRef, StringRef> &' but is initialized with type 'std::pair<const llvm::StringRef, llvm::StringRef>' resulting in a copy<br>
llvm/tools/llvm-vtabledump/llvm-vtabledump.cpp:366:8: note: use non-reference type 'const std::pair<StringRef, StringRef>' to keep the copy or type 'const std::pair<const llvm::StringRef, llvm::StringRef> &' to prevent copying<br>
llvm/utils/TableGen/CodeGenRegisters.cpp:1773:24: error: loop variable 'SUI' is always a copy because the range of type 'const RegUnitList' (aka 'const SparseBitVector<>') does not return a reference<br>
llvm/utils/TableGen/CodeGenRegisters.cpp:1773:12: note: use non-reference type 'const unsigned int'<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
<a href="http://reviews.llvm.org/D4169" target="_blank">http://reviews.llvm.org/D4169</a><br>
<br>
EMAIL PREFERENCES<br>
<a href="http://reviews.llvm.org/settings/panel/emailpreferences/" target="_blank">http://reviews.llvm.org/settings/panel/emailpreferences/</a><br>
<br>
<br>
</div></div></blockquote></div><br></div></div>