================
@@ -1035,10 +1137,39 @@ bool createParameters(NewFunction &ExtractedFunc,
TypeInfo.addConst();
}
}
+
+ // C has no references. A parameter that would otherwise need one
+ // becomes a real pointer instead: the call site takes the address of
+ // the original variable explicitly, and every use of it in the
+ // copied-out body is rewritten into a dereference (see
+ // NewFunction::getFuncBody). Array types are the exception: they decay
+ // to a pointer on their own wherever they're used, so no rewriting or
+ // address-of is needed for them at all.
+ if (Kind == ParamPassKind::Reference && !LangOpts.CPlusPlus) {
+ if (TypeInfo->isArrayType()) {
+ Kind = ParamPassKind::Value;
----------------
ArcsinX wrote:
Array type is something like `int[10]` and `NewFunction::Parameter::render()`
will produce uncompilable code like `int[10] A`.
So, I guess we need a special handling for arrays to replace `int[5]` with `int
*`, maybe we can do this by changing `TypeInfo` here, thus `type + " " + name`
still will be ok for arrays too.
Maybe we can also take into account a case when we extract to function code
containing `sizeof(arr)`, because `sizeof` for pointer is not the same as
`sizeof` for array
https://github.com/llvm/llvm-project/pull/228465
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits