public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-6591] Test to verify -Wformat-overflow uses context-sensitive ranges.
@ 2022-01-14 17:02 Martin Sebor
  0 siblings, 0 replies; only message in thread
From: Martin Sebor @ 2022-01-14 17:02 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1e6294bb15d2169147c7838f89a9168980b94b47

commit r12-6591-g1e6294bb15d2169147c7838f89a9168980b94b47
Author: Martin Sebor <msebor@redhat.com>
Date:   Fri Jan 14 09:59:53 2022 -0700

    Test to verify -Wformat-overflow uses context-sensitive ranges.
    
    gcc/testsuite/ChangeLog:
            * gcc.dg/tree-ssa/builtin-sprintf-warn-28.c: New test.

Diff:
---
 .../gcc.dg/tree-ssa/builtin-sprintf-warn-28.c       | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-28.c b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-28.c
new file mode 100644
index 00000000000..d58d9808279
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/builtin-sprintf-warn-28.c
@@ -0,0 +1,21 @@
+/* Verify that -Wformat-overflow uses context-sensitive ranges even
+   at -O0 to avoid both false positives and negatives.
+   { dg-do compile }
+   { dg-options "-O0 -Wall" } */
+
+extern int sprintf (char*, const char*, ...);
+
+extern char a[4];
+
+void test_context_range (int c)
+{
+  int i = 998;
+
+  /* Prior to the switch to Ranger in GCC 12 -Wformat-overflow triggers
+     for both calls because EVRP doesn't expose the accurate range of
+     the argument.  */
+  if (c)
+    sprintf (a, "%i", i + 2);   // { dg-warning "writing a terminating nul past the end of the destination" }
+  else
+    sprintf (a, "%i", i + 1);   // { dg-bogus "-Wformat-overflow" }
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-01-14 17:02 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-14 17:02 [gcc r12-6591] Test to verify -Wformat-overflow uses context-sensitive ranges Martin Sebor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).