public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: David Malcolm <dmalcolm@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-5640] analyzer: verify that -Wanalyzer-too-complex can be disabled via pragmas [PR100524] Date: Tue, 30 Nov 2021 22:50:08 +0000 (GMT) [thread overview] Message-ID: <20211130225008.55ABF3858D3C@sourceware.org> (raw) 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
reply other threads:[~2021-11-30 22:50 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211130225008.55ABF3858D3C@sourceware.org \ --to=dmalcolm@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).