public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Tim Lange <mail@tim-lange.me>
To: dmalcolm@redhat.com, gcc-patches@gcc.gnu.org
Cc: Tim Lange <mail@tim-lange.me>
Subject: [PATCH 2/2] testsuite: Add more allocation size tests for conjured svalues [PR110014]
Date: Fri,  9 Jun 2023 20:28:13 +0200	[thread overview]
Message-ID: <20230609182813.72319-2-mail@tim-lange.me> (raw)
In-Reply-To: <20230609182813.72319-1-mail@tim-lange.me>

This patch adds the reproducers reported in PR 110014 as test cases. The
false positives in those cases are already fixed with PR 109577.

2023-06-09  Tim Lange  <mail@tim-lange.me>

	PR analyzer/110014

gcc/testsuite/ChangeLog:

	* gcc.dg/analyzer/pr110014.c: New tests.

---
 gcc/testsuite/gcc.dg/analyzer/pr110014.c | 25 ++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/analyzer/pr110014.c

diff --git a/gcc/testsuite/gcc.dg/analyzer/pr110014.c b/gcc/testsuite/gcc.dg/analyzer/pr110014.c
new file mode 100644
index 00000000000..d76b8781413
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/pr110014.c
@@ -0,0 +1,25 @@
+void *realloc (void *, unsigned long)
+  __attribute__((__nothrow__, __leaf__))
+  __attribute__((__warn_unused_result__)) __attribute__((__alloc_size__ (2)));
+
+long *
+slurp (long *buffer, unsigned long file_size)
+{
+  unsigned long cc;
+  if (!__builtin_add_overflow (file_size - file_size % sizeof (long),
+			       2 * sizeof (long), &cc))
+    buffer = realloc (buffer, cc);
+  return buffer;
+}
+
+long *
+slurp1 (long *buffer, unsigned long file_size)
+{
+  return realloc (buffer, file_size - file_size % sizeof (long));
+}
+
+long *
+slurp2 (long *buffer, unsigned long file_size)
+{
+  return realloc (buffer, (file_size / sizeof (long)) * sizeof (long));
+}
-- 
2.40.1


  reply	other threads:[~2023-06-09 18:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-09 18:28 [PATCH 1/2] analyzer: Fix allocation size false positive on conjured svalue [PR109577] Tim Lange
2023-06-09 18:28 ` Tim Lange [this message]
2023-06-09 20:21   ` [PATCH 2/2] testsuite: Add more allocation size tests for conjured svalues [PR110014] David Malcolm
2023-06-09 20:17 ` [PATCH 1/2] analyzer: Fix allocation size false positive on conjured svalue [PR109577] David Malcolm

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=20230609182813.72319-2-mail@tim-lange.me \
    --to=mail@tim-lange.me \
    --cc=dmalcolm@redhat.com \
    --cc=gcc-patches@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: link
Be 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).