[COMMITTED] add test for false positive -Wformat-overflow in a loop [PR81401]

Message ID 2768fc1d-efd0-06c3-9597-9dffa1493a08@gmail.com
State New
Headers show
Series
  • [COMMITTED] add test for false positive -Wformat-overflow in a loop [PR81401]
Related show

Commit Message

Martin Sebor March 4, 2020, 5:31 p.m.
The bug has been fixed for a while.  I added the two tests from
the report in 97bd1d6b513..3ca63e1c76b (attached).

Martin

Patch

commit 3ca63e1c76b7693b5d3f5ba2567421defc764249 (HEAD -> master)
Author: Martin Sebor <msebor@redhat.com>
Date:   Wed Mar 4 10:23:49 2020 -0700

    PR middle-end/81401 - false positive -Wformat-overflow in a loop
    
    gcc/testsuite/ChangeLog:
            * gcc.dg/tree-ssa/builtin-sprintf-warn-24.c: New test.

diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 83882d2ecf6..b28eb52f8a5 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@ 
+2020-03-04  Martin Sebor  <msebor@redhat.com>
+
+       PR middle-end/81401
+       * gcc.dg/tree-ssa/builtin-sprintf-warn-24.c: New test.
+
 2020-03-04  Will Schmidt  <will_schmidt@vnet.ibm.com>
 
        * gcc.target/powerpc/20050603-3.c: Remove XFAILS.
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-24.c b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-24.c
new file mode 100644
index 00000000000..d9109781d84
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-24.c
@@ -0,0 +1,22 @@ 
+/* PR middle-end/81401 - false positive -Wformat-overflow in a loop
+   { dg-do compile }
+   { dg-options "-O2 -Wall -Wformat-overflow" } */
+
+char a[3];
+
+void f (void)
+{
+  int i, i0 = 0x00;
+
+  for (i = i0; i <= 0xff; ++i)
+    __builtin_sprintf (a, "%02x", i);   // { dg-bogus "\\\[-Wformat-overflow" }
+}
+
+char b[2];
+
+void g (void)
+{
+  int i;
+  for (i = 0; i < 10; ++i)
+    __builtin_sprintf (b, "%d", i);     // { dg-bogus "\\\[-Wformat-overflow" }
+}