public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-5640] analyzer: verify that -Wanalyzer-too-complex can be disabled via pragmas [PR100524]
@ 2021-11-30 22:50 David Malcolm
0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2021-11-30 22:50 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:03ea0ca1189a39e095188b0425c66446cc84a0a5
commit r12-5640-g03ea0ca1189a39e095188b0425c66446cc84a0a5
Author: David Malcolm <dmalcolm@redhat.com>
Date: Tue Nov 30 14:21:31 2021 -0500
analyzer: verify that -Wanalyzer-too-complex can be disabled via pragmas [PR100524]
gcc/testsuite/ChangeLog:
PR analyzer/100524
* gcc.dg/analyzer/pragma-2.c: New test.
Signed-off-by: David Malcolm <dmalcolm@redhat.com>
Diff:
---
gcc/testsuite/gcc.dg/analyzer/pragma-2.c | 57 ++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/gcc/testsuite/gcc.dg/analyzer/pragma-2.c b/gcc/testsuite/gcc.dg/analyzer/pragma-2.c
new file mode 100644
index 00000000000..58fcaab11df
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/pragma-2.c
@@ -0,0 +1,57 @@
+/* Verify that we can disable -Wanalyzer-too-complex via pragmas. */
+/* { dg-additional-options "-Wanalyzer-too-complex -Werror=analyzer-too-complex -fno-analyzer-state-merge -g" } */
+
+#include <stdlib.h>
+
+extern int get (void);
+
+/* In theory each of p0...p4 can be in various malloc states,
+ independently, so the total combined number of states
+ at any program point within the loop is NUM_VARS * NUM_STATES. */
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wanalyzer-too-complex"
+
+void test (void)
+{
+ void *p0 = NULL, *p1 = NULL, *p2 = NULL, *p3 = NULL, *p4 = NULL;
+ void **pp = NULL;
+ while (get ())
+ {
+ switch (get ())
+ {
+ default:
+ case 0:
+ pp = &p0;
+ break;
+ case 1:
+ pp = &p1;
+ break;
+ case 2:
+ pp = &p2;
+ break;
+ case 3:
+ pp = &p3;
+ break;
+ case 4:
+ pp = &p4;
+ break;
+ }
+
+ switch (get ())
+ {
+ default:
+ case 0:
+ *pp = malloc (16); /* { dg-warning "leak" } */
+ break;
+ case 1:
+ free (*pp);
+ break;
+ case 2:
+ /* no-op. */
+ break;
+ }
+ }
+}
+
+#pragma GCC diagnostic pop
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-11-30 22:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-30 22:50 [gcc r12-5640] analyzer: verify that -Wanalyzer-too-complex can be disabled via pragmas [PR100524] David Malcolm
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).