[PATCH 01/15] stdio-common: Don't read real input beyond the field width in scanf [BZ #13988]

Maciej W. Rozycki macro@redhat.com
Thu Jun 5 18:00:01 GMT 2025


On Mon, 2 Jun 2025, Maciej W. Rozycki wrote:

> > The latter seems quite reasonable to me.
> 
>  However sadly both variants result in worse machine code produced:
> 
> $ size -G stdio-common/vfscanf-internal-?.o
>       text       data        bss      total filename
>      27248        303          0      27551 stdio-common/vfscanf-internal-0.o
>      28036        303          0      28339 stdio-common/vfscanf-internal-1.o
>      27264        303          0      27567 stdio-common/vfscanf-internal-2.o
> $ 
> 
> I can see extra register spills even with the second replacement variant 
> (I didn't bother to look through the first one as grossly worse).  This is 
> with GCC 14 on `powerpc64le-linux-gnu'.
> 
>  Would factoring out the (avail == 0 && (c = EOF)) expression to a macro 
> with a side effect (analogous to that of `inchar') be an acceptable 
> compromise?
> 
>  Or shall we just choose to live with it and instead challenge the GCC 
> optimiser to produce better code, given that the code quality regression 
> isn't that substantial?

 No further feedback received and my experiments have shown that the macro 
variant seems good in terms of coding style and also causes a substantial 
code size *reduction*, for a change, compared to the original variant:

      text       data        bss      total filename
     27248        303          0      27551 stdio-common/vfscanf-internal-0.o
     27120        303          0      27423 stdio-common/vfscanf-internal-3.o

which I find a good sign, so I've posted v2 now with that update included 
and also 09/15 removed as promised.

 Thank you for your review.

  Maciej



More information about the Libc-alpha mailing list