From: David Malcolm Date: Tue, 30 Nov 2021 19:21:31 +0000 (-0500) Subject: analyzer: verify that -Wanalyzer-too-complex can be disabled via pragmas [PR100524] X-Git-Tag: basepoints/gcc-13~2673 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03ea0ca1189a39e095188b0425c66446cc84a0a5;p=thirdparty%2Fgcc.git 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 --- 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 000000000000..58fcaab11df5 --- /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 + +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