[clang-tools-extra] [clangd] Extract to function: Pass unmodified scalar parameters by value (PR #227675)
Aleksandr Platonov via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 1 00:12:08 PDT 2026
================
@@ -1014,15 +1014,25 @@ bool createParameters(NewFunction &ExtractedFunc,
return false;
// Parameter qualifiers are same as the Decl's qualifiers.
QualType TypeInfo = VD->getType().getNonReferenceType();
- // Add const if it's not (conservatively) mutated in the zone: it's
- // still passed by reference to avoid a copy, but the reference doesn't
- // need to be mutable. Array types are never made const: mutating array
- // elements through a non-const-ref loop variable or a decayed pointer
- // argument is common and easy to miss conservatively, so we don't try.
- if (!DeclInfo.IsPossiblyMutated && !TypeInfo->isArrayType())
- TypeInfo.addConst();
// FIXME: check if parameter will be a non l-value reference.
bool IsPassedByReference = true;
+ if (!DeclInfo.IsPossiblyMutated) {
+ // A scalar (arithmetic, pointer, enumeration, ...) is at least as
+ // cheap to copy as to pass by reference, and less noisy. Any
----------------
ArcsinX wrote:
I guess that for large scalar types this still makes sense to pass by reference.
E.g. `_BitInt(N)` is a scalar type. So, maybe we can add a check and still pass by reference if scalar type size ` > 2 * sizeof(void *)`
https://github.com/llvm/llvm-project/pull/227675
More information about the cfe-commits
mailing list