]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
analyzer: verify that -Wanalyzer-too-complex can be disabled via pragmas [PR100524]
authorDavid Malcolm <dmalcolm@redhat.com>
Tue, 30 Nov 2021 19:21:31 +0000 (14:21 -0500)
committerDavid Malcolm <dmalcolm@redhat.com>
Tue, 30 Nov 2021 22:49:04 +0000 (17:49 -0500)
gcc/testsuite/ChangeLog:
PR analyzer/100524
* gcc.dg/analyzer/pragma-2.c: New test.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/testsuite/gcc.dg/analyzer/pragma-2.c [new file with mode: 0644]

diff --git a/gcc/testsuite/gcc.dg/analyzer/pragma-2.c b/gcc/testsuite/gcc.dg/analyzer/pragma-2.c
new file mode 100644 (file)
index 0000000..58fcaab
--- /dev/null
@@ -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