[DWARF] Fix signedness issue in DWARF functions (1)
Eric Botcazou
botcazou@adacore.com
Mon Apr 26 16:48:52 GMT 2021
Hi,
the compiler can synthesize DWARF functions to describe the location and size
of components in discriminated record types with variant part in Ada, but a
limitation is that most quantities must have DWARF2_ADDR_SIZE or else be the
result of a zero-extension to DWARF2_ADDR_SIZE of a smaller quantity, as
documented in loc_list_from_tree_1:
/* ??? Most of the time we do not take proper care for sign/zero
extending the values properly. Hopefully this won't be a real
problem... */
Now in Ada discriminants may be either signed or unsigned, so this limitation
is problematic. Therefore the attached patch adds a strict_signedness field
to the loc_descr_context that is passed around in parts of the DWARF back-end
and changes loc_list_from_tree_1 to act upon it being set to true. It also
contains a small optimization to avoid emitting useless comparisons with 0.
Tested on x86-64/Linux, both GCC and GDB, OK for the mainline?
2021-04-26 Eric Botcazou <ebotcazou@adacore.com>
* dwarf2out.c (scompare_loc_descriptor): Fix head comment.
(is_handled_procedure_type): Likewise.
(struct loc_descr_context): Add strict_signedness field.
(resolve_args_picking_1): Deal with DW_OP_[GNU_]deref_type,
DW_OP_[GNU_]convert and DW_OP_[GNU_]reinterpret.
(resolve_args_picking): Minor tweak.
(function_to_dwarf_procedure): Initialize strict_signedness field.
(type_byte_size): Likewise.
(field_byte_offset): Likewise.
(gen_descr_array_type_die): Likewise.
(gen_variant_part): Likewise.
(loc_list_from_tree_1) <CALL_EXPR>: Tidy up and set strict_signedness
to true when a context is present before evaluating the arguments.
<COND_EXPR>: Do not generate a useless comparison with zero.
When dereferencing an address, if strict_signedness is true and the
type is small and signed, use DW_OP_deref_type to do the dereference
and then DW_OP_convert to convert back to the generic type.
--
Eric Botcazou
-------------- next part --------------
A non-text attachment was scrubbed...
Name: p.diff
Type: text/x-patch
Size: 13369 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210426/f2029ce4/attachment-0001.bin>
More information about the Gcc-patches
mailing list