PR middle-end/81401 - false positive -Wformat-overflow in a loop
authorMartin Sebor <msebor@redhat.com>
Wed, 4 Mar 2020 17:23:49 +0000 (10:23 -0700)
committerMartin Sebor <msebor@redhat.com>
Wed, 4 Mar 2020 17:23:49 +0000 (10:23 -0700)
gcc/testsuite/ChangeLog:
* gcc.dg/tree-ssa/builtin-sprintf-warn-24.c: New test.

gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-24.c [new file with mode: 0644]

index 83882d2ecf63afabe4cab1ebc4e4b004cde3e8f0..b28eb52f8a56b1190d832c81bda798cde61297f0 100644 (file)
@@ -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 (file)
index 0000000..d910978
--- /dev/null
@@ -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" }
+}