================
@@ -419,6 +458,63 @@ void insertArgCoercion(FunctionOpInterface funcOp,
BlockArgument blockArg = entry.getArgument(blockArgIdx);
+ if (auto flatTy = getFlattenedCoercedType(ac)) {
+ // Direct + canFlatten: the coerced type is a struct whose fields become
+ // individual wire arguments. The reconstruction mirrors the Expand path
+ // — replace the single block arg with N scalar block args, store them
+ // into an alloca of the coerced struct type, reload — but then applies
+ // an additional coercion from the coerced struct type to the original
+ // argument type if the two differ in layout.
+ unsigned numFields = flatTy.getNumElements();
+ assert(numFields >= 2 && "getFlattenedCoercedType guarantees >1 fields");
+ Type origTy = blockArg.getType();
+ Location loc = funcOp.getLoc();
+
+ // Change slot 0 to field 0's type; insert slots 1..N-1 after it.
+ blockArg.setType(flatTy.getElementType(0));
+ for (unsigned f = 1; f < numFields; ++f)
+ entry.insertArgument(blockArgIdx + f, flatTy.getElementType(f), loc);
----------------
adams381 wrote:
Kept the index-based loop instead. The iterator overload
`Block::insertArgument(args_iterator, Type, Location)` is implemented as
`insertArgument(it->getArgNumber(), ...)`, so it dereferences the iterator.
This arm appends the trailing fields, so after slot 0 the insertion point is
`args_end()` (for a single-arg callee `args_begin() + blockArgIdx + 1` already
is `args_end()`), and `it->getArgNumber()` there is out of bounds. The
`unsigned` overload asserts `index <= arguments.size()`, so appending is only
valid through the index form. Also `cir::RecordType` exposes `getMembers()`,
not `getElements()`, so the suggestion as written wouldn't compile.
https://github.com/llvm/llvm-project/pull/201719
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits