On Mon, Jun 3, 2024 at 11:18 AM Eric Botcazou <botca...@adacore.com> wrote:
>
> Hi,
>
> for the attached Ada package declaring a simple variable-sized record type,
> the compiler builds a "size function" in GENERIC which is at -Og:
>
> sizetype _GLOBAL.SZ5_p (p__enum p0)
> {
>   return (UNSIGNED_8) p0 + 252 <= 3 ? 32 : 0;
> }
>
> The UNSIGNED_8-based trick eliminates one branch but relies on the wrap-around
> arithmetics of UNSIGNED_8.  This size function is then translated into a DWARF
> procedure, but the wrap-around arithmetics is dropped, leading to a wrong size
> calculation when the DWARF procedure is executed.
>
> The fix also contains an optimization of unsigned comparisons in DWARF for the
> case where the type is smaller than the "generic type", as is the case here.
>
> Tested on x86-64/Linux, OK for the mainline?

OK.

Thanks,
Richard.

>
> 2024-06-03  Eric Botcazou  <ebotca...@adacore.com>
>
>         * dwarf2out.cc (loc_list_from_tree_1) <CEIL_DIV_EXPR>; Add const.
>         <do_comp_binop>: Use a signed comparison for small unsigned types.
>         Implement wrap-around arithmetics for small integer types.
>
> --
> Eric Botcazou

Reply via email to