[PATCH] fold: Fix up strn{case,}cmp folding [PR98771]
Jakub Jelinek
jakub@redhat.com
Sun Jan 31 13:12:46 GMT 2021
On Sun, Jan 31, 2021 at 01:49:29PM +0100, Eric Botcazou wrote:
> > The important difference is for strn{,case}cmp folding, we pass that s2
> > value as the last argument to the host functions comparing the c_getstr
> > results. If s2 fits into size_t, then my patch makes no difference,
> > but if it is larger, we know the 2 c_getstr objects need to fit into the
> > host address space, so larger s2 should just act essentially as strcmp
> > or strcasecmp; as none of those objects can occupy 100% of the address
> > space, using MIN (SIZE_MAX, s2) achieves that.
>
> But SIZE_MAX is a host value, isn't it? As a matter of fact, it breaks the
Sure.
> build with somewhat ancient glibcs:
>
> In file included from ../../src/gcc/fold-const-call.c:21:
>
> ../../src/gcc/fold-const-call.c: In function 'tree_node*
> fold_const_call(combined_fn, tree, tree, tree, tree)':
>
> ../../src/gcc/fold-const-call.c:1777:56: error: 'SIZE_MAX' was not declared in
> this scope
>
> 1777 | return build_int_cst (type, strncmp (p0, p1, MIN (s2, SIZE_MAX)));
>
> because /usr/include/stdint.h has:
>
> /* The ISO C99 standard specifies that in C++ implementations these
> macros should only be defined if explicitly requested. */
> #if !defined __cplusplus || defined __STDC_LIMIT_MACROS
Ugh. Anyway, we don't really need the SIZE_MAX macro, we can use
INTTYPE_MAXIMUM (size_t) or (~(size_t) 0) too instead of it.
Jakub
More information about the Gcc-patches
mailing list