On Tue, 8 Feb 2022, LIU Hao wrote:
在 2/8/22 16:33, Martin Storsjö 写道:
On Sun, 6 Feb 2022, Pali Rohár wrote:
Mark _vscprintf() and _scprintf() functions with attribute pure as their
return value depends only on passed arguments.
In function __ms_vsnprintf() check only for n==0 and move _vscprintf()
call
at the end of function. This allows LTO to optimize out _vscprintf() call
from __ms_vsnprintf() function if caller of snprintf() or vsnprintf() does
not use return value.
It works because _vscprintf() is direct return value of __ms_vsnprintf()
and function marked as pure is automatically optimized out if its return
value is not used.
---
mingw-w64-crt/stdio/vsnprintf.c | 10 +++++-----
mingw-w64-headers/crt/stdio.h | 3 +++
2 files changed, 8 insertions(+), 5 deletions(-)
This looks ok to me, so I pushed it.
Please use `__pure__` instead of `pure` in standard library headers. The
latter is subject to user-defined macros.
Oh, right, sorry for missing that bit.
Although I have no objection against this patch, I do wonder whether it is
practical to build the CRT with LTO. There are some symbols (e.g. the TLS
directory) that mean to 'be there unconditionally', which might be stripped
by LTO and cause undefined references (I thought I had seen this before, not
sure).
Yeah, it's probably a cornercase in itself, but the patch seemed harmless
anyway.
// Martin
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public