From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2209) id 7E55C3858C54; Wed, 5 Oct 2022 18:08:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7E55C3858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1664993287; bh=c9MYwIBbT1IHOWagk0Ea+PCXpu90jMByFfz86+aVtrA=; h=From:To:Subject:Date:From; b=uAyL5yTvhn0ydRKOY4TXMTyEkY6/Ev/vBeB7qNcLknAfd1T8yOIgTT7mXq3mAyZNq Ze24gL6i048CLvH6cFhpt2jKl0kI4cVaUulobK+BN/t/R9rait4aA8pGHpEGKGUsQA TXf77tHmI9bvq9cfP4Q2gmwFE3K5EX35NDm2DNi4= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: David Malcolm To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3096] analyzer: add regression test for PR 107158 X-Act-Checkin: gcc X-Git-Author: David Malcolm X-Git-Refname: refs/heads/master X-Git-Oldrev: 2eff4fe383a59de94267352e25f77b29d8e6bb42 X-Git-Newrev: ef878564140cbcf23f479da88e07e5a996cec6bb Message-Id: <20221005180807.7E55C3858C54@sourceware.org> Date: Wed, 5 Oct 2022 18:08:07 +0000 (GMT) List-Id: https://gcc.gnu.org/g:ef878564140cbcf23f479da88e07e5a996cec6bb commit r13-3096-gef878564140cbcf23f479da88e07e5a996cec6bb Author: David Malcolm Date: Wed Oct 5 14:07:47 2022 -0400 analyzer: add regression test for PR 107158 PR analyzer/107158 reports an ICE when using -fanalyzer -fanalyzer-call-summaries on a particular source file. It turns out I just fixed this ICE in r13-3094-g6832c95c0e1a58. This followup patch adds a somewhat reduced reproducer as a regression test. Unfortunately, although the ICE is fixed, there are two false positives from -Wanalyzer-malloc-leak on the test case, so I'm going to use PR analyzer/107158 for tracking those false positives. gcc/testsuite/ChangeLog: PR analyzer/107158 * gcc.dg/analyzer/call-summaries-pr107158.c: New test. Signed-off-by: David Malcolm Diff: --- .../gcc.dg/analyzer/call-summaries-pr107158.c | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/gcc/testsuite/gcc.dg/analyzer/call-summaries-pr107158.c b/gcc/testsuite/gcc.dg/analyzer/call-summaries-pr107158.c new file mode 100644 index 00000000000..54f442f0ad4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/analyzer/call-summaries-pr107158.c @@ -0,0 +1,83 @@ +/* { dg-additional-options "-fanalyzer-call-summaries" } */ + +typedef __SIZE_TYPE__ size_t; +enum { _ISspace = ((5) < 8 ? ((1 << (5)) << 8) : ((1 << (5)) >> 8)) }; +extern const unsigned short int **__ctype_b_loc(void) + __attribute__((__nothrow__, __leaf__, __const__)); +extern void *malloc(size_t __size) + __attribute__((__nothrow__, __leaf__, __malloc__, __alloc_size__(1))); +extern char *strcpy(char *__restrict __dest, const char *__restrict __src) + __attribute__((__nothrow__, __leaf__, __nonnull__(1, 2))); +extern size_t strlen(const char *__s) + __attribute__((__nothrow__, __leaf__, __pure__, __nonnull__(1))); + +struct mydata { + struct mydata *link; + char *name; + char *type; +}; + +static struct mydata *all_data; +static int line_no; + +__attribute__((__noreturn__)) void failed(const char *message); + +static char *string_dup(const char *string) { + char *buf; + + if ((buf = malloc(strlen(string) + 1)) == ((void *)0)) + failed("malloc() failed"); + + return strcpy(buf, string); +} + +static void store_data(const char *name, const char *type) { + struct mydata *p, *q; + + if ((p = (struct mydata *)malloc(sizeof(struct mydata))) == ((void *)0)) + failed("malloc() failed"); + + p->link = ((void *)0); + p->name = string_dup(name); + p->type = string_dup(type); + + if ((q = all_data) == ((void *)0)) + all_data = p; + else { + while (q->link != ((void *)0)) + q = q->link; + q->link = p; + } +} + +static void parse_tbl(char *buffer) { + char *s = buffer; + char *t = s + strlen(s); + + do { + t--; + if (((*__ctype_b_loc())[(int)(((int)*t))] & (unsigned short int)_ISspace)) + *t = '\0'; + else + break; + } while (t > s); + while (((*__ctype_b_loc())[(int)(((int)*s))] & (unsigned short int)_ISspace)) + s++; + buffer = s; + + line_no++; + if (*buffer != ';' && *buffer != '\0') { + if (*buffer == '#') { + store_data(buffer, ""); /* { dg-bogus "leak" "PR analyzer/107158" { xfail *-*-* } } */ + } else { + + while (*s && !((*__ctype_b_loc())[(int)(((int)*s))] & + (unsigned short int)_ISspace)) + s++; + while ( + ((*__ctype_b_loc())[(int)(((int)*s))] & (unsigned short int)_ISspace)) + *s++ = '\0'; + store_data(buffer, s); /* { dg-bogus "leak" "PR analyzer/107158" { xfail *-*-* } } */ + } + } +}