diff options
author | Jakub Jelinek <jakub@redhat.com> | 2024-04-30 11:22:32 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2024-04-30 11:22:32 +0200 |
commit | 6c6b70f07208ca14ba783933988c04c6fc2fff42 (patch) | |
tree | 886a6f741348fb5535efe6ec4dda4c54cd6f508f /gcc/c | |
parent | 6d4593a178b49cab205d81cdf36f52e12eabbc6d (diff) | |
download | gcc-6c6b70f07208ca14ba783933988c04c6fc2fff42.zip gcc-6c6b70f07208ca14ba783933988c04c6fc2fff42.tar.gz gcc-6c6b70f07208ca14ba783933988c04c6fc2fff42.tar.bz2 |
gimple-ssa-sprintf: Use [0, 1] range for %lc with (wint_t) 0 argument [PR114876]
Seems when Martin S. implemented this, he coded there strict reading
of the standard, which said that %lc with (wint_t) 0 argument is handled
as wchar_t[2] temp = { arg, 0 }; %ls with temp arg and so shouldn't print
any values. But, most of the libc implementations actually handled that
case like %c with '\0' argument, adding a single NUL character, the only
known exception is musl.
Recently, C23 changed this in response to GB-141 and POSIX in
https://austingroupbugs.net/view.php?id=1647
so that it should have the same behavior as %c with '\0'.
Because there is implementation divergence, the following patch uses
a range rather than hardcoding it to all 1s (i.e. the %c behavior),
though the likely case is still 1 (forward looking plus most of
implementations).
The res.knownrange = true; assignment removed is redundant due to
the same assignment done unconditionally before the if statement,
rest is formatting fixes.
I don't think the min >= 0 && min < 128 case is right either, I'd think
it should be min >= 0 && max < 128, otherwise it is just some possible
inputs are (maybe) ASCII and there can be others, but this code is a total
mess anyway, with the min, max, likely (somewhere in [min, max]?) and then
unlikely possibly larger than max, dunno, perhaps for at least some chars
in the ASCII range the likely case could be for the ascii case; so perhaps
just the one_2_one_ascii shouldn't set max to 1 and mayfail should be true
for max >= 128. Anyway, didn't feel I should touch that right now.
2024-04-30 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/114876
* gimple-ssa-sprintf.cc (format_character): For min == 0 && max == 0,
set max, likely and unlikely members to 1 rather than 0. Remove
useless res.knownrange = true;. Formatting fixes.
* gcc.dg/pr114876.c: New test.
* gcc.dg/tree-ssa/builtin-sprintf-warn-1.c: Adjust expected
diagnostics.
Diffstat (limited to 'gcc/c')
0 files changed, 0 insertions, 0 deletions