handle case where C returns by-value, but roc wants to return by-pointer

This commit is contained in:
Folkert 2022-09-08 21:03:58 +02:00 committed by Richard Feldman
parent a0fe1ec453
commit d725e44538
No known key found for this signature in database
GPG key ID: F1F21AA5B1D9E43B

View file

@ -6607,7 +6607,7 @@ fn to_cc_type_builtin<'a, 'ctx, 'env>(
}
}
#[derive(Clone, Copy)]
#[derive(Debug, Clone, Copy)]
enum RocReturn {
/// Return as normal
Return,
@ -6951,7 +6951,16 @@ fn build_foreign_symbol<'a, 'ctx, 'env>(
builder.build_return(Some(&return_value));
}
RocReturn::ByPointer => {
debug_assert!(matches!(cc_return, CCReturn::ByPointer));
match cc_return {
CCReturn::Return => {
let result = call.try_as_basic_value().left().unwrap();
env.builder.build_store(return_pointer, result);
}
CCReturn::ByPointer | CCReturn::Void => {
// the return value (if any) is already written to the return pointer
}
}
builder.build_return(None);
}