From: Martin Sebor Date: Wed, 28 Sep 2016 19:51:08 +0000 (+0000) Subject: PR middle-end/77721 - -Wformat-length not uses arg range for converted vars X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=88000fd1dcfa85b7909ffa3cc40a18c577f26e25;p=gcc.git PR middle-end/77721 - -Wformat-length not uses arg range for converted vars gcc/testsuite/ChangeLog: PR middle-end/77721 * gcc.dg/tree-ssa/builtin-sprintf-warn-6.c: New test. From-SVN: r240595 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f1a8803cda6..ca1ded4b17b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-09-28 Martin Sebor + + PR middle-end/77721 + * gcc.dg/tree-ssa/builtin-sprintf-warn-6.c: New test. + 2016-09-28 Jerry DeLisle PR libgfortran/77707 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-6.c b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-6.c new file mode 100644 index 00000000000..1a9df982d71 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-6.c @@ -0,0 +1,92 @@ +/* PR middle-end/77721 - -Wformat-length not uses arg range for converted vars + Test to verify that the correct range information is made available to the + -Wformat-lenght check to prevent warnings. */ +/* { dg-do compile } */ +/* { dg-options "-O2 -Wformat -Wformat-length" } */ + +int snprintf (char*, __SIZE_TYPE__, const char*, ...); + +void fuchar (unsigned char j, char *p) +{ + if (j > 99) + return; + snprintf (p, 4, "%3hu", j); +} + +void fschar (signed char j, char *p) +{ + const unsigned char k = (unsigned char) j; + + if (k > 99) + return; + + snprintf (p, 3, "%3hhu", k); /* { dg-bogus "" "unsigned char" { xfail *-*-* } } */ +} + +void fushrt (unsigned short j, char *p) +{ + if (j > 999) + return; + snprintf (p, 4, "%3hu", j); +} + +void fshrt (short j, char *p) +{ + const unsigned short k = (unsigned short) j; + + if (k > 999) + return; + + snprintf (p, 4, "%3hu", k); +} + +void fuint (unsigned j, char *p) +{ + if (j > 999) + return; + snprintf (p, 4, "%3u", j); +} + +void fint (int j, char *p) +{ + const unsigned k = (unsigned) j; + + if (k > 999) + return; + + snprintf (p, 4, "%3u", k); /* { dg-bogus "" "unsigned int" { xfail *-*-* } } */ +} + +void fulong (unsigned long j, char *p) +{ + if (j > 999) + return; + snprintf (p, 4, "%3lu", j); +} + +void flong (long j, char *p) +{ + const unsigned long k = (unsigned long) j; + + if (k > 999) + return; + + snprintf (p, 4, "%3lu", k); /* { dg-bogus "" "unsigned long" { xfail *-*-* } } */ +} + +void fullong (unsigned long long j, char *p) +{ + if (j > 999) + return; + snprintf (p, 4, "%3llu", j); +} + +void fllong (long j, char *p) +{ + const unsigned long long k = (unsigned long long) j; + + if (k > 999) + return; + + snprintf (p, 4, "%3llu", k); /* { dg-bogus "" "unsigned long long" { xfail *-*-* } } */ +}