From 9f662787e0b1bc31d89395aa7d07a5d9f4ac44df Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Thu, 9 Jun 2005 10:34:03 +0000 Subject: [PATCH] get struct copy to/from struct fields via pointers. fixes a bug found by snax --- tools/qfcc/source/constfold.c | 2 +- tools/qfcc/source/emit.c | 10 ++++++++++ tools/qfcc/source/immediate.c | 4 +++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tools/qfcc/source/constfold.c b/tools/qfcc/source/constfold.c index 24783544a..6398597f6 100644 --- a/tools/qfcc/source/constfold.c +++ b/tools/qfcc/source/constfold.c @@ -1147,7 +1147,7 @@ static operation_t op_struct[ev_type_count] = { do_op_invalid, // ev_entity do_op_invalid, // ev_field do_op_invalid, // ev_func - do_op_invalid, // ev_pointer + do_op_pointer, // ev_pointer do_op_invalid, // ev_quaternion do_op_invalid, // ev_integer do_op_invalid, // ev_uinteger diff --git a/tools/qfcc/source/emit.c b/tools/qfcc/source/emit.c index b5848f4d1..5bb25f799 100644 --- a/tools/qfcc/source/emit.c +++ b/tools/qfcc/source/emit.c @@ -419,6 +419,16 @@ emit_deref_expr (expr_t *e, def_t *dest) dest->file = e->file; dest->users += 2; } + if (dest->type->type == ev_struct) { + expr_t *d = new_def_expr (dest); + expr_t *m = new_move_expr (d, e, dest->type); + d->line = dest->line; + d->file = dest->file; + m->line = e->line; + m->file = e->file; + emit_sub_expr (m, 0); + return dest; + } if (e->type == ex_expr && e->e.expr.op == '&' diff --git a/tools/qfcc/source/immediate.c b/tools/qfcc/source/immediate.c index ce0f8522d..301c03631 100644 --- a/tools/qfcc/source/immediate.c +++ b/tools/qfcc/source/immediate.c @@ -277,8 +277,10 @@ ReuseConstant (expr_t *expr, def_t *def) reloc_def_field_ofs (e.e.pointer.def, cn->ofs); break; case ex_pointer: - if (e.e.pointer.def) + if (e.e.pointer.def) { EMIT_DEF_OFS (G_INT (cn->ofs), e.e.pointer.def); + e.e.pointer.def->users--; + } break; default: break;