[2/2] testsuite: Add more allocation size tests for conjured svalues [PR110014]

Message ID 20230609182813.72319-2-mail@tim-lange.me
State New
Headers
Series [1/2] analyzer: Fix allocation size false positive on conjured svalue [PR109577] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Testing passed

Commit Message

Tim Lange June 9, 2023, 6:28 p.m. UTC
  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
  

Comments

David Malcolm June 9, 2023, 8:21 p.m. UTC | #1
On Fri, 2023-06-09 at 20:28 +0200, Tim Lange wrote:
> 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.

Please can you rename the new test case to 
"realloc-pr110014.c" (since having too many test cases named simply
prXXXXXX.c gets overwhelming).

Approved for trunk once the fix for PR 109577 goes in

Thanks!
Dave
  

Patch

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));
+}