@@ -2492,7 +2492,8 @@ static void
24922492riscv_call_arg_scalar_int (struct riscv_arg_info * ainfo ,
24932493 struct riscv_call_info * cinfo )
24942494{
2495- if (ainfo -> length > (2 * cinfo -> xlen ))
2495+ if (TYPE_HAS_DYNAMIC_LENGTH (ainfo -> type )
2496+ || ainfo -> length > (2 * cinfo -> xlen ))
24962497 {
24972498 /* Argument is going to be passed by reference. */
24982499 ainfo -> argloc [0 ].loc_type
@@ -2910,8 +2911,12 @@ riscv_arg_location (struct gdbarch *gdbarch,
29102911 break ;
29112912
29122913 case TYPE_CODE_STRUCT :
2913- riscv_call_arg_struct (ainfo , cinfo );
2914- break ;
2914+ if (!TYPE_HAS_DYNAMIC_LENGTH (ainfo -> type ))
2915+ {
2916+ riscv_call_arg_struct (ainfo , cinfo );
2917+ break ;
2918+ }
2919+ /* FALLTHROUGH */
29152920
29162921 default :
29172922 riscv_call_arg_scalar_int (ainfo , cinfo );
@@ -3228,13 +3233,6 @@ riscv_return_value (struct gdbarch *gdbarch,
32283233 struct riscv_arg_info info ;
32293234 struct type * arg_type ;
32303235
3231- gdb_byte * readbuf = nullptr ;
3232- if (read_value != nullptr )
3233- {
3234- * read_value = allocate_value (type );
3235- readbuf = value_contents_raw (* read_value ).data ();
3236- }
3237-
32383236 arg_type = check_typedef (type );
32393237 riscv_arg_location (gdbarch , & info , & call_info , arg_type , false);
32403238
@@ -3246,15 +3244,15 @@ riscv_return_value (struct gdbarch *gdbarch,
32463244 gdb_printf (gdb_stdlog , "\n" );
32473245 }
32483246
3249- if (readbuf != nullptr || writebuf != nullptr )
3247+ if (read_value != nullptr || writebuf != nullptr )
32503248 {
32513249 unsigned int arg_len ;
32523250 struct value * abi_val ;
3253- gdb_byte * old_readbuf = nullptr ;
3251+ gdb_byte * readbuf = nullptr ;
32543252 int regnum ;
32553253
32563254 /* We only do one thing at a time. */
3257- gdb_assert (readbuf == nullptr || writebuf == nullptr );
3255+ gdb_assert (read_value == nullptr || writebuf == nullptr );
32583256
32593257 /* In some cases the argument is not returned as the declared type,
32603258 and we need to cast to or from the ABI type in order to
@@ -3295,7 +3293,6 @@ riscv_return_value (struct gdbarch *gdbarch,
32953293 else
32963294 {
32973295 abi_val = allocate_value (info .type );
3298- old_readbuf = readbuf ;
32993296 readbuf = value_contents_raw (abi_val ).data ();
33003297 }
33013298 arg_len = info .type -> length ();
@@ -3375,8 +3372,17 @@ riscv_return_value (struct gdbarch *gdbarch,
33753372
33763373 regcache_cooked_read_unsigned (regcache , RISCV_A0_REGNUM ,
33773374 & addr );
3378- if (readbuf != nullptr )
3379- read_memory (addr , readbuf , info .length );
3375+ if (read_value != nullptr )
3376+ {
3377+ abi_val = value_at_non_lval (type , addr );
3378+ /* Also reset the expected type, so that the cast
3379+ later on is a no-op. If the cast is not a no-op,
3380+ and if the return type is variably-sized, then the
3381+ type of ABI_VAL will differ from ARG_TYPE due to
3382+ dynamic type resolution, and so will most likely
3383+ fail. */
3384+ arg_type = value_type (abi_val );
3385+ }
33803386 if (writebuf != nullptr )
33813387 write_memory (addr , writebuf , info .length );
33823388 }
@@ -3391,10 +3397,8 @@ riscv_return_value (struct gdbarch *gdbarch,
33913397 /* This completes the cast from abi type back to the declared type
33923398 in the case that we are reading from the machine. See the
33933399 comment at the head of this block for more details. */
3394- if (readbuf != nullptr )
3400+ if (read_value != nullptr )
33953401 {
3396- struct value * arg_val ;
3397-
33983402 if (is_fixed_point_type (arg_type ))
33993403 {
34003404 /* Convert abi_val to the actual return type, but
@@ -3405,15 +3409,13 @@ riscv_return_value (struct gdbarch *gdbarch,
34053409 unscaled .read (value_contents (abi_val ),
34063410 type_byte_order (info .type ),
34073411 info .type -> is_unsigned ());
3408- arg_val = allocate_value (arg_type );
3409- unscaled .write (value_contents_raw (arg_val ),
3412+ * read_value = allocate_value (arg_type );
3413+ unscaled .write (value_contents_raw (* read_value ),
34103414 type_byte_order (arg_type ),
34113415 arg_type -> is_unsigned ());
34123416 }
34133417 else
3414- arg_val = value_cast (arg_type , abi_val );
3415- memcpy (old_readbuf , value_contents_raw (arg_val ).data (),
3416- arg_type -> length ());
3418+ * read_value = value_cast (arg_type , abi_val );
34173419 }
34183420 }
34193421
0 commit comments