Manna created this revision. Manna added reviewers: erichkeane, aaron.ballman. Herald added subscribers: manas, ASDenysPetrov, dkrupp, donat.nagy, Szelethus, arphaman, a.sidorin, baloghadamsoftware. Herald added a project: All. Manna requested review of this revision. Herald added a project: clang.
Reported by Coverity: Big parameter passed by value Copying large values is inefficient, consider passing by reference; Low, medium, and high size thresholds for detection can be adjusted. 1. Inside "SemaConcept.cpp" file, in subsumes<clang::Sema::MaybeEmitAmbiguousAtomicConstraintsDiagnostic(clang::NamedDecl *, llvm::ArrayRef<clang::Expr const *>, clang::NamedDecl *, llvm::ArrayRef<clang::Expr const *>)::[lambda(clang::AtomicConstraint const &, clang::AtomicConstraint const &) (instance 2)]>(llvm::SmallVector<llvm::SmallVector<clang::AtomicConstraint *, 2u>, 4u>, llvm::SmallVector<llvm::SmallVector<clang::AtomicConstraint *, 2u>, 4u>, T1): A large function call parameter exceeding the low threshold is passed by value. i. pass_by_value: Passing parameter PDNF of type NormalForm (size 144 bytes) by value, which exceeds the low threshold of 128 bytes. ii. pass_by_value: Passing parameter QCNF of type NormalForm (size 144 bytes) by value, which exceeds the low threshold of 128 bytes. 2. Inside "CodeGenAction.cpp" file, in clang::reportOptRecordError(llvm::Error, clang::DiagnosticsEngine &, clang::CodeGenOptions): A very large function call parameter exceeding the high threshold is passed by value. i. pass_by_value: Passing parameter CodeGenOpts of type clang::CodeGenOptions const (size 1560 bytes) by value, which exceeds the high threshold of 512 bytes. 3. Inside "CodeCompleteConsumer.cpp" file, in clang::PrintingCodeCompleteConsumer::ProcessCodeCompleteResults(clang::Sema &, clang::CodeCompletionContext, clang::CodeCompletionResult *, unsigned int): A large function call parameter exceeding the low threshold is passed by value. i. pass_by_value: Passing parameter Context of type clang::CodeCompletionContext (size 200 bytes) by value, which exceeds the low threshold of 128 bytes. 4. Inside "GlobalModuleIndex.cpp" file, in clang::GlobalModuleIndex::GlobalModuleIndex(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::BitstreamCursor): A large function call parameter exceeding the medium threshold is passed by value. i. pass_by_value: Passing parameter Cursor of type llvm::BitstreamCursor (size 352 bytes) by value, which exceeds the medium threshold of 256 bytes. 5. Inside "CGNonTrivialStruct.cpp" file, in <unnamed>::getParamAddrs<1ull, <0ull...>>(std::integer_sequence<unsigned long long, T2...>, std::array<clang::CharUnits, T1>, clang::CodeGen::FunctionArgList, clang::CodeGen::CodeGenFunction *): A large function call parameter exceeding the low threshold is passed by value. i. pass_by_value: Passing parameter Args of type clang::CodeGen::FunctionArgList (size 144 bytes) by value, which exceeds the low threshold of 128 bytes. 6. Inside "CodeGenModule.cpp" file, in clang::CodeGen::CodeGenModule::EmitBackendOptionsMetadata(clang::CodeGenOptions): A very large function call parameter exceeding the high threshold is passed by value. i. pass_by_value: Passing parameter CodeGenOpts of type clang::CodeGenOptions const (size 2008 bytes) by value, which exceeds the high threshold of 512 bytes. 7. Inside "SemaCodeComplete.cpp" file, in HandleCodeCompleteResults(clang::Sema *, clang::CodeCompleteConsumer *, clang::CodeCompletionContext, clang::CodeCompletionResult *, unsigned int): A large function call parameter exceeding the low threshold is passed by value. i. pass_by_value: Passing parameter Context of type clang::CodeCompletionContext (size 200 bytes) by value, which exceeds the low threshold of 128 bytes. 8. Inside "CGGPUBuiltin.cpp" file, in <unnamed>::containsNonScalarVarargs(clang::CodeGen::CodeGenFunction *, clang::CodeGen::CallArgList): A very large function call parameter exceeding the high threshold is passed by value. i. pass_by_value: Passing parameter Args of type clang::CodeGen::CallArgList (size 1176 bytes) by value, which exceeds the high threshold of 512 bytes. 9. Inside "ASTUnit.cpp" file, in <unnamed>::AugmentedCodeCompleteConsumer::ProcessCodeCompleteResults(clang::Sema &, clang::CodeCompletionContext, clang::CodeCompletionResult *, unsigned int): A large function call parameter exceeding the low threshold is passed by value. i. pass_by_value: Passing parameter Context of type clang::CodeCompletionContext (size 200 bytes) by value, which exceeds the low threshold of 128 bytes. 10. Inside "SemaConcept.cpp" file, in <unnamed>::SatisfactionStackRAII::SatisfactionStackRAII(clang::Sema &, clang::NamedDecl const *, llvm::FoldingSetNodeID): A large function call parameter exceeding the low threshold is passed by value. i. pass_by_value: Passing parameter FSNID of type llvm::FoldingSetNodeID (size 144 bytes) by value, which exceeds the low threshold of 128 bytes. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D147708 Files: clang/lib/CodeGen/CGGPUBuiltin.cpp clang/lib/CodeGen/CGNonTrivialStruct.cpp clang/lib/CodeGen/CodeGenAction.cpp clang/lib/CodeGen/CodeGenModule.cpp clang/lib/Frontend/ASTUnit.cpp clang/lib/Sema/CodeCompleteConsumer.cpp clang/lib/Sema/SemaCodeComplete.cpp clang/lib/Sema/SemaConcept.cpp clang/lib/Sema/SemaInit.cpp clang/lib/Serialization/GlobalModuleIndex.cpp
Index: clang/lib/Serialization/GlobalModuleIndex.cpp =================================================================== --- clang/lib/Serialization/GlobalModuleIndex.cpp +++ clang/lib/Serialization/GlobalModuleIndex.cpp @@ -127,7 +127,7 @@ GlobalModuleIndex::GlobalModuleIndex( std::unique_ptr<llvm::MemoryBuffer> IndexBuffer, - llvm::BitstreamCursor Cursor) + llvm::BitstreamCursor &Cursor) : Buffer(std::move(IndexBuffer)), IdentifierIndex(), NumIdentifierLookups(), NumIdentifierLookupHits() { auto Fail = [&](llvm::Error &&Err) { Index: clang/lib/Sema/SemaInit.cpp =================================================================== --- clang/lib/Sema/SemaInit.cpp +++ clang/lib/Sema/SemaInit.cpp @@ -5287,7 +5287,7 @@ // Process entities (i.e. array members, base classes, or class fields) by // adding an initialization expression to InitExprs for each entity to // initialize. - auto ProcessEntities = [&](auto Range) -> bool { + auto ProcessEntities = [&](auto &Range) -> bool { bool IsUnionType = Entity.getType()->isUnionType(); for (InitializedEntity SubEntity : Range) { // Unions should only have one initializer expression. Index: clang/lib/Sema/SemaConcept.cpp =================================================================== --- clang/lib/Sema/SemaConcept.cpp +++ clang/lib/Sema/SemaConcept.cpp @@ -160,7 +160,7 @@ Sema &SemaRef; bool Inserted = false; SatisfactionStackRAII(Sema &SemaRef, const NamedDecl *ND, - llvm::FoldingSetNodeID FSNID) + llvm::FoldingSetNodeID &FSNID) : SemaRef(SemaRef) { if (ND) { SemaRef.PushSatisfactionStackEntry(ND, FSNID); @@ -1370,7 +1370,7 @@ } template<typename AtomicSubsumptionEvaluator> -static bool subsumes(NormalForm PDNF, NormalForm QCNF, +static bool subsumes(NormalForm &PDNF, NormalForm &QCNF, AtomicSubsumptionEvaluator E) { // C++ [temp.constr.order] p2 // Then, P subsumes Q if and only if, for every disjunctive clause Pi in the Index: clang/lib/Sema/SemaCodeComplete.cpp =================================================================== --- clang/lib/Sema/SemaCodeComplete.cpp +++ clang/lib/Sema/SemaCodeComplete.cpp @@ -4148,7 +4148,7 @@ static void HandleCodeCompleteResults(Sema *S, CodeCompleteConsumer *CodeCompleter, - CodeCompletionContext Context, + CodeCompletionContext &Context, CodeCompletionResult *Results, unsigned NumResults) { if (CodeCompleter) Index: clang/lib/Sema/CodeCompleteConsumer.cpp =================================================================== --- clang/lib/Sema/CodeCompleteConsumer.cpp +++ clang/lib/Sema/CodeCompleteConsumer.cpp @@ -638,8 +638,8 @@ } void PrintingCodeCompleteConsumer::ProcessCodeCompleteResults( - Sema &SemaRef, CodeCompletionContext Context, CodeCompletionResult *Results, - unsigned NumResults) { + Sema &SemaRef, CodeCompletionContext &Context, + CodeCompletionResult *Results, unsigned NumResults) { std::stable_sort(Results, Results + NumResults); if (!Context.getPreferredType().isNull()) Index: clang/lib/Frontend/ASTUnit.cpp =================================================================== --- clang/lib/Frontend/ASTUnit.cpp +++ clang/lib/Frontend/ASTUnit.cpp @@ -2064,7 +2064,7 @@ } void AugmentedCodeCompleteConsumer::ProcessCodeCompleteResults(Sema &S, - CodeCompletionContext Context, + CodeCompletionContext &Context, CodeCompletionResult *Results, unsigned NumResults) { // Merge the results we were given with the results we cached. Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -990,7 +990,7 @@ } void CodeGenModule::EmitBackendOptionsMetadata( - const CodeGenOptions CodeGenOpts) { + const CodeGenOptions &CodeGenOpts) { if (getTriple().isRISCV()) { getModule().addModuleFlag(llvm::Module::Min, "SmallDataLimit", CodeGenOpts.SmallDataLimit); Index: clang/lib/CodeGen/CodeGenAction.cpp =================================================================== --- clang/lib/CodeGen/CodeGenAction.cpp +++ clang/lib/CodeGen/CodeGenAction.cpp @@ -86,7 +86,7 @@ }; static void reportOptRecordError(Error E, DiagnosticsEngine &Diags, - const CodeGenOptions CodeGenOpts) { + const CodeGenOptions &CodeGenOpts) { handleAllErrors( std::move(E), [&](const LLVMRemarkSetupFileError &E) { Index: clang/lib/CodeGen/CGNonTrivialStruct.cpp =================================================================== --- clang/lib/CodeGen/CGNonTrivialStruct.cpp +++ clang/lib/CodeGen/CGNonTrivialStruct.cpp @@ -323,7 +323,7 @@ template <size_t N, size_t... Ints> static std::array<Address, N> getParamAddrs(std::index_sequence<Ints...> IntSeq, std::array<CharUnits, N> Alignments, - FunctionArgList Args, + FunctionArgList &Args, CodeGenFunction *CGF) { return std::array<Address, N>{ {Address(CGF->Builder.CreateLoad(CGF->GetAddrOfLocalVar(Args[Ints])), Index: clang/lib/CodeGen/CGGPUBuiltin.cpp =================================================================== --- clang/lib/CodeGen/CGGPUBuiltin.cpp +++ clang/lib/CodeGen/CGGPUBuiltin.cpp @@ -125,7 +125,7 @@ } } -bool containsNonScalarVarargs(CodeGenFunction *CGF, CallArgList Args) { +bool containsNonScalarVarargs(CodeGenFunction *CGF, CallArgList &Args) { return llvm::any_of(llvm::drop_begin(Args), [&](const CallArg &A) { return !A.getRValue(*CGF).isScalar(); });
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits