Reuse the previous record assignment code. Use gen(expr) to generate
the fir::ExtendedValue of parent component recursively and convert the
structure to a fir.ref<T> type, where T is the record type of parent
component. Then, fir:🏭:genRecordAssignment can be reused to
assign the parent component to the type-casted structure.
Details
Diff Detail
Event Timeline
flang/lib/Lower/ConvertExpr.cpp | ||
---|---|---|
1069 | I think you can simply convert res to a fir.ref<T> where T is the recordType of from, and call fir::factory::genRecordAssignment(builder, loc, resCast, from);. This should deal with the case where the runtime needs to be called without making a full copy of from before calling th | |
flang/lib/Optimizer/Builder/FIRBuilder.cpp | ||
1053 | I do not follow why this change was required. Doesn't llvm::zip already safely take the smallest of the two lists as iteration size ? I think the new code could segafult at compile time if genComponentByComponentAssignment was called with a lhs that has less components than the rhs (which would of course be a compiler bug) | |
1180 | I think you can avoid adding genParentCompAssigment and all this by calling genRecordAssignment (the mutable box trick is a bit weird, better to keep it in one place). |
Thanks @jeanPerier a lot for the suggestions.
I do not follow why this change was required. Doesn't llvm::zip already safely take the smallest of the two lists as iteration size ? I think the new code could segafult at compile time if genComponentByComponentAssignment was called with a lhs that has less components than the rhs (which would of course be a compiler bug)
Right. I had thought llvm::zip requires the size of two list to be the same. I was wrong.
flang/lib/Lower/ConvertExpr.cpp | ||
---|---|---|
1069 | Good idea. This makes things much simple. Thanks for this. |
I think you can simply convert res to a fir.ref<T> where T is the recordType of from, and call fir::factory::genRecordAssignment(builder, loc, resCast, from);. This should deal with the case where the runtime needs to be called without making a full copy of from before calling th