From: Tom de Vries Date: Thu, 27 Nov 2025 11:52:03 +0000 (+0100) Subject: [gdb/tdep] Simplify i386_thiscall_push_dummy_call X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=24ea21fe77db8b3e6d8e4c91cd137fc537718a4a;p=thirdparty%2Fbinutils-gdb.git [gdb/tdep] Simplify i386_thiscall_push_dummy_call I came across this code in i386_thiscall_push_dummy_call: ... int args_space = 0; ... for (write_pass = 0; write_pass < 2; write_pass++) { int args_space_used = 0; ... if (write_pass) { store_unsigned_integer (buf, 4, byte_order, struct_addr); write_memory (sp, buf, 4); args_space_used += 4; } else args_space += 4; ... and wondered about the difference between arg_space and arg_space_used. AFAICT, there is none: - args_space is available after the loop, but unused after the loop - in the loop body: - if write_pass == 0: args_space is used - if write_pass == 1: arg_space_used - the code modifying args_space and args_space_used is identical Simplify the loop body by using just one variable: args_space. Tested on x86_64-linux with target board unix/-m32. --- diff --git a/gdb/i386-tdep.c b/gdb/i386-tdep.c index b201d2a4139..8996b80f5bc 100644 --- a/gdb/i386-tdep.c +++ b/gdb/i386-tdep.c @@ -2691,7 +2691,6 @@ i386_thiscall_push_dummy_call (struct gdbarch *gdbarch, struct value *function, gdb_byte buf[4]; int i; int write_pass; - int args_space = 0; /* Determine the total space required for arguments and struct return address in a first pass (allowing for 16-byte-aligned @@ -2699,7 +2698,7 @@ i386_thiscall_push_dummy_call (struct gdbarch *gdbarch, struct value *function, for (write_pass = 0; write_pass < 2; write_pass++) { - int args_space_used = 0; + int args_space = 0; if (return_method == return_method_struct) { @@ -2708,38 +2707,30 @@ i386_thiscall_push_dummy_call (struct gdbarch *gdbarch, struct value *function, /* Push value address. */ store_unsigned_integer (buf, 4, byte_order, struct_addr); write_memory (sp, buf, 4); - args_space_used += 4; } - else - args_space += 4; + + args_space += 4; } for (i = thiscall ? 1 : 0; i < nargs; i++) { int len = args[i]->enclosing_type ()->length (); + if (i386_16_byte_align_p (args[i]->enclosing_type ())) + args_space = align_up (args_space, 16); + if (write_pass) - { - if (i386_16_byte_align_p (args[i]->enclosing_type ())) - args_space_used = align_up (args_space_used, 16); + write_memory (sp + args_space, + args[i]->contents_all ().data (), len); - write_memory (sp + args_space_used, - args[i]->contents_all ().data (), len); - /* The System V ABI says that: + /* The System V ABI says that: - "An argument's size is increased, if necessary, to make it a - multiple of [32-bit] words. This may require tail padding, - depending on the size of the argument." + "An argument's size is increased, if necessary, to make it a + multiple of [32-bit] words. This may require tail padding, + depending on the size of the argument." - This makes sure the stack stays word-aligned. */ - args_space_used += align_up (len, 4); - } - else - { - if (i386_16_byte_align_p (args[i]->enclosing_type ())) - args_space = align_up (args_space, 16); - args_space += align_up (len, 4); - } + This makes sure the stack stays word-aligned. */ + args_space += align_up (len, 4); } if (!write_pass)