From 090b4bc46c6d08a47d0dd3b15910beec38f6f26c Mon Sep 17 00:00:00 2001 From: Robert Pengelly Date: Thu, 8 Oct 2026 05:30:44 +0100 Subject: [PATCH] i386/amd64: Fix structure assignment from dereferenced pointers --- amd64.c | 15 +++++++++++++++ i386.c | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/amd64.c b/amd64.c index 37673ed..540bf19 100644 --- a/amd64.c +++ b/amd64.c @@ -32916,6 +32916,21 @@ static int parse_identifier_assignment_statement (void) { lhs_is_floating = lhs ? lhs->is_floating : get_global_symbol_floating (name); lhs_pointer_depth = lhs ? lhs->pointer_depth : get_global_symbol_pointer_depth (name); + if (is_simple_assign && lhs_size > (DATA_LLONG & 0x1f) && tok.kind == TOK_STAR) { + + emit_load_symbol_address_for_copy_now ("rdx", lhs, name); + + if (emit_aggregate_copy_from_current_rhs_to_addr_reg_now ("rdx", 0, lhs_size)) { + + expect_semi_or_recover (); + + free (name); + return 1; + + } + + } + if (is_simple_assign && lhs_size > (DATA_LLONG & 0x1f) && tok.kind == TOK_IDENT) { char *rhs_name = xstrdup (tok.ident); diff --git a/i386.c b/i386.c index 647e550..6db590c 100644 --- a/i386.c +++ b/i386.c @@ -30369,6 +30369,21 @@ static int parse_identifier_assignment_statement (void) { lhs_size = lhs ? lhs->size : get_global_symbol_size (name); lhs_is_floating = lhs ? lhs->is_floating : get_global_symbol_floating (name); + if (is_simple_assign && lhs_size > (DATA_LLONG & 0x1f) && tok.kind == TOK_STAR) { + + emit_load_symbol_address_for_copy_now ("edx", lhs, name); + + if (emit_aggregate_copy_from_current_rhs_to_addr_reg_now ("edx", 0, lhs_size)) { + + expect_semi_or_recover (); + + free (name); + return 1; + + } + + } + if (is_simple_assign && lhs_size > (DATA_LLONG & 0x1f) && tok.kind == TOK_IDENT) { char *rhs_name = xstrdup (tok.ident); -- 2.34.1