mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-15 18:08:10 +00:00
A function with a value return form, such as `->? form(val C)`, is lowered to return the value representation of `C`: a pointer for types with a pointer value representation. However, lowering of `ReturnExpr` re-derived the return convention independently of the function's signature, and assumed that any returned value expression was a `returned var`, taking the initializing-return path. For types with an in-place initializing representation, that tried to initialize a nonexistent return slot and crashed. (This only appeared to work for types like `i32`, whose by-copy initializing representation happens to match the value representation.) Fix this by recording how the function returns its result -- `void`, by copy, by reference, in place via an `sret` parameter, or as the entry point's implicit `i32` -- as a `ReturnKind` in `FunctionTypeInfo` and `FunctionInfo` when the signature is lowered, and having the `Return` and `ReturnExpr` handlers switch on it. This keeps the signature and the `return` lowering in agreement by construction, and replaces the `IsEntryPoint` check in `Return` lowering.