On Tue, Jan 11, 2022 at 02:27:48PM +0530, Siddhesh Poyarekar wrote:
> Handle hints provided by __attribute__ ((access (...))) to compute
> dynamic sizes for objects.
>
> gcc/ChangeLog:
>
> * tree-object-size.c: Include tree-dfa.h.
> (parm_object_size): New function.
> (collect_object_sizes_for): Call it.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.dg/builtin-dynamic-object-size-0.c (test_parmsz_simple,
> test_parmsz_scaled, test_parmsz_unknown): New functions.
> (main): Call them. Add new arguments argc and argv.
>
> Signed-off-by: Siddhesh Poyarekar <[email protected]>
> + /* Walk through the parameters to pick the size parameter and safely
> + scale it by the type size. */
> + for (arg = fnargs; arg; arg = TREE_CHAIN (arg), ++argpos)
> + {
> + if (argpos == access->sizarg && INTEGRAL_TYPE_P (TREE_TYPE (arg)))
> + {
> + sz = get_or_create_ssa_default_def (cfun, arg);
> + if (sz != NULL_TREE)
> + {
> + sz = fold_convert (sizetype, sz);
> + if (typesize)
> + sz = size_binop (MULT_EXPR, sz, typesize);
> + }
> + break;
> + }
> + }
No need for those {}s around the if as body of for, just use
for (arg = fnargs; arg; arg = TREE_CHAIN (arg), ++argpos)
if (argpos == access->sizarg && INTEGRAL_TYPE_P (TREE_TYPE (arg)))
{
...
break;
}
Ok with that change.
Jakub