Commit 31c87a43 by Martin Sebor Committed by Martin Sebor

PR middle-end/78703 - fprintf-return-value floating point handling incorrect in…

PR middle-end/78703 - fprintf-return-value floating point handling incorrect in locales with a mulltibyte decimal point

gcc/ChangeLog:
        PR middle-end/78703
        * gimple-ssa-sprintf.c (adjust_for_width_or_precision): Change
        to accept adjustment as an array.
        (get_int_range): New function.
        (struct directive): Make width and prec arrays.
        (directive::set_width, directive::set_precision): Call get_int_range.
        (format_integer, format_floating): Handle width and precision ranges.
        (format_string, parse_directive): Same.

gcc/testsuite/ChangeLog:
        PR middle-end/78703
        * gcc.dg/tree-ssa/builtin-snprintf-warn-1.c: Update
        * gcc.dg/tree-ssa/builtin-sprintf-warn-9.c: Rename...
        * gcc.dg/tree-ssa/builtin-sprintf-warn-10.c: ...to this.
        * gcc.dg/tree-ssa/builtin-sprintf-warn-9.c: New test.

From-SVN: r244956
parent b0670cc0
2017-01-26 Martin Sebor <msebor@redhat.com>
PR middle-end/78703
* gimple-ssa-sprintf.c (adjust_for_width_or_precision): Change
to accept adjustment as an array.
(get_int_range): New function.
(struct directive): Make width and prec arrays.
(directive::set_width, directive::set_precision): Call get_int_range.
(format_integer, format_floating): Handle width and precision ranges.
(format_string, parse_directive): Same.
2017-01-26 Jakub Jelinek <jakub@redhat.com>
PR debug/79129
......
2017-01-26 Martin Sebor <msebor@redhat.com>
PR middle-end/78703
* gcc.dg/tree-ssa/builtin-snprintf-warn-1.c: Update
* gcc.dg/tree-ssa/builtin-sprintf-warn-9.c: Rename...
* gcc.dg/tree-ssa/builtin-sprintf-warn-10.c: ...to this.
* gcc.dg/tree-ssa/builtin-sprintf-warn-9.c: New test.
2017-01-26 Jakub Jelinek <jakub@redhat.com>
PR debug/79129
......
......@@ -4,6 +4,9 @@
typedef struct
{
char a0[0];
/* Separate a0 from a1 to prevent the former from being substituted
for the latter and causing false positives. */
int: 8;
char a1[1];
char a2[2];
char a3[3];
......@@ -23,11 +26,13 @@ int value_range (int min, int max)
#define R(min, max) value_range (min, max)
extern void sink (void*);
/* Verify that calls to snprintf whose return value is unused are
diagnosed if certain or possible truncation is detected. */
#define T(size, ...) \
__builtin_snprintf (buffer (size), size, __VA_ARGS__)
__builtin_snprintf (buffer (size), size, __VA_ARGS__), sink (buffer)
void test_int_retval_unused (void)
{
......@@ -39,9 +44,20 @@ void test_int_retval_unused (void)
void test_string_retval_unused (const Arrays *ar)
{
/* At level 1 strings of unknown length are assumed to be empty so
the following is not diagnosed. */
T (1, "%-s", ar->a0);
/* A one-byte array can only hold an empty string, so the following
isn't diagnosed. */
T (1, "%-s", ar->a1);
T (1, "%-s", ar->a2); /* { dg-warning "output may be truncated" } */
/* Unlike the ar->a0 case above, at level 1, the length of an unknown
string that points to an array of known size is assumed to be the
size of the array minus 1. */
T (1, "%-s", ar->a2); /* { dg-warning "output may be truncated" } */
T (1, "%-s", ar->a3); /* { dg-warning "output may be truncated" } */
T (1, "%-s", ar->a4); /* { dg-warning "output may be truncated" } */
/* Same as the ar->a0 case above. */
T (1, "%-s", ar->ax);
}
......@@ -68,6 +84,7 @@ void test_string_retval_used (const Arrays *ar)
T (1, "%-s", ar->a0);
T (1, "%-s", ar->a1);
T (1, "%-s", ar->a2);
T (1, "%-s", ar->a3);
T (1, "%-s", ar->a4);
T (1, "%-s", "123"); /* { dg-warning "output truncated" } */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment