diff options
| author | gingerBill <bill@gingerbill.org> | 2019-07-27 10:20:11 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2019-07-27 10:20:11 +0100 |
| commit | f3bffb98101e3a584c8a5e8a6389c608ffe64c40 (patch) | |
| tree | 1de3f067a441934fc7d5ed5f69e6171cae7443d9 /src | |
| parent | 540730c0bedb7f6e107d2ed01c804f897074419d (diff) | |
Improvement to the Odin calling conventions to pass certain things by "implicit reference" (`const &` in C++)
Diffstat (limited to 'src')
| -rw-r--r-- | src/check_type.cpp | 8 | ||||
| -rw-r--r-- | src/entity.cpp | 3 | ||||
| -rw-r--r-- | src/ir.cpp | 3 |
3 files changed, 11 insertions, 3 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp index f4e5b49d0..5b20a48fc 100644 --- a/src/check_type.cpp +++ b/src/check_type.cpp @@ -2084,6 +2084,14 @@ void set_procedure_abi_types(CheckerContext *c, Type *type) { Type *original_type = e->type; Type *new_type = type_to_abi_compat_param_type(c->allocator, original_type, type->Proc.calling_convention); type->Proc.abi_compat_params[i] = new_type; + switch (type->Proc.calling_convention) { + case ProcCC_Odin: + case ProcCC_Contextless: + if (is_type_pointer(new_type) & !is_type_pointer(e->type)) { + e->flags |= EntityFlag_ImplicitReference; + } + break; + } } } diff --git a/src/entity.cpp b/src/entity.cpp index 3318eac24..0c05a9bf6 100644 --- a/src/entity.cpp +++ b/src/entity.cpp @@ -48,7 +48,8 @@ enum EntityFlag { EntityFlag_NotExported = 1<<14, EntityFlag_Static = 1<<16, - // EntityFlag_Reference = 1<<17, + + EntityFlag_ImplicitReference = 1<<17, // NOTE(bill): equivalent to `const &` in C++ EntityFlag_CVarArg = 1<<20, EntityFlag_AutoCast = 1<<21, diff --git a/src/ir.cpp b/src/ir.cpp index 82f9fa755..8c5dcb963 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -3004,9 +3004,8 @@ irValue *ir_emit_call(irProcedure *p, irValue *value, Array<irValue *> args, Pro if (are_types_identical(arg_type, new_type)) { // NOTE(bill): Done } else if (!are_types_identical(original_type, new_type)) { - if (is_type_pointer(new_type) && !is_type_pointer(original_type)) { - if (e->flags&EntityFlag_Value) { + if (e->flags&EntityFlag_ImplicitReference) { args[i] = ir_address_from_load_or_generate_local(p, args[i]); } else if (!is_type_pointer(arg_type)) { args[i] = ir_copy_value_to_ptr(p, args[i], original_type, 16); |