Back in decemeber we had a conversation about __builtin_memcpy_chk and
related testcases in the presence of the new points to code.
The conversation is here:
https://gcc.gnu.org/pipermail/gcc-patches/2025-December/703714.html
These all appear to be testcase expectation issues rather than
correctness problems.
The integrated PTA is able to infer additional pointer equivalences and
object size information that were previously unavailable (for example,
proving pointer identity through arithmetic and propagating known object
sizes into |_chk|builtins). As a result, some |_chk|calls are now
optimized away where tests expected them to remain, while in other cases
|_chk|calls are preserved because object sizes are now known where they
were previously treated as unknown. The |execute/builtins|harness also
intentionally tracks and constrains certain builtin transformations,
which makes it somewhat sensitive to optimizer precision improvements.
The resulting testcase adjustments reflect changed optimizer knowledge
rather than semantic regressions.
UNless someone has an alternative change, this is what I plan to commit
with the PTA patch
From fdc5a32f3c66fc0fdd11c1dab0306ef15302c48b Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <[email protected]>
Date: Mon, 15 Dec 2025 16:27:35 -0500
Subject: [PATCH 3/8] Points-to fix for _chk testcases.
Adjust or remove the lines which PTA invalidates.
The enhanced prange PTA exposes additional object identity and offset information that the existing tests did not previously see. As a result, some _chk builtin tests fail because they encode assumptions about previous imprecision: either expecting an object to remain unknown, expecting a _chk call to remain, or expecting one to be folded only under older object-size behaviour.
gcc/testsuite/
* gcc.c-torture/execute/builtins/memcpy-chk.c: Adjust.
* gcc.c-torture/execute/builtins/memmove-chk.c: Adjust.
* gcc.c-torture/execute/builtins/strncat-chk.c: Adjust.
---
.../gcc.c-torture/execute/builtins/memcpy-chk.c | 4 ++--
.../gcc.c-torture/execute/builtins/memmove-chk.c | 4 ++--
.../gcc.c-torture/execute/builtins/strncat-chk.c | 14 --------------
3 files changed, 4 insertions(+), 18 deletions(-)
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/memcpy-chk.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memcpy-chk.c
index 5b245e58e22..985e1ad2368 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/memcpy-chk.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memcpy-chk.c
@@ -146,7 +146,7 @@ test2_sub (long *buf3, char *buf4, char *buf6, int n)
call. */
/* buf3 points to an unknown object, so __memcpy_chk should not be done. */
- if (memcpy ((char *) buf3 + 4, buf5, n + 6) != (char *) buf1 + 4
+ if (memcpy ((char *) buf3 + 4, buf5, 6) != (char *) buf1 + 4
|| memcmp (buf1, "aBcdRSTUVWklmnopq\0", 19))
abort ();
@@ -158,7 +158,7 @@ test2_sub (long *buf3, char *buf4, char *buf6, int n)
|| i != 3)
abort ();
- if (memcpy ((char *) buf3 + 14, buf6, n + 2) != (char *) buf1 + 14
+ if (memcpy ((char *) buf3 + 14, buf6, 2) != (char *) buf1 + 14
|| memcmp (buf1, "aBcdRSTUVWkSmnrsq\0", 19))
abort ();
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/memmove-chk.c b/gcc/testsuite/gcc.c-torture/execute/builtins/memmove-chk.c
index 73b35883ed1..fbecf313ed1 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/memmove-chk.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/memmove-chk.c
@@ -149,7 +149,7 @@ test2_sub (long *buf3, char *buf4, char *buf6, int n)
call. */
/* buf3 points to an unknown object, so __memmove_chk should not be done. */
- if (memmove ((char *) buf3 + 4, buf5, n + 6) != (char *) buf1 + 4
+ if (memmove ((char *) buf3 + 4, buf5, 6) != (char *) buf1 + 4
|| memcmp (buf1, "aBcdRSTUVWklmnopq\0", 19))
abort ();
@@ -161,7 +161,7 @@ test2_sub (long *buf3, char *buf4, char *buf6, int n)
|| i != 3)
abort ();
- if (memmove ((char *) buf3 + 14, buf6, n + 2) != (char *) buf1 + 14
+ if (memmove ((char *) buf3 + 14, buf6, 2) != (char *) buf1 + 14
|| memcmp (buf1, "aBcdRSTUVWkSmnrsq\0", 19))
abort ();
diff --git a/gcc/testsuite/gcc.c-torture/execute/builtins/strncat-chk.c b/gcc/testsuite/gcc.c-torture/execute/builtins/strncat-chk.c
index 8904df14aee..a110b4c4bef 100644
--- a/gcc/testsuite/gcc.c-torture/execute/builtins/strncat-chk.c
+++ b/gcc/testsuite/gcc.c-torture/execute/builtins/strncat-chk.c
@@ -67,20 +67,6 @@ test1 (void)
abort ();
strcat_disallowed = 0;
- /* These __strncat_chk calls should be optimized into __strcat_chk,
- as strlen (src) <= len. */
- strcpy (dst, s1);
- if (strncat (dst, "foo", 3) != dst || strcmp (dst, "hello worldfoo"))
- abort ();
- strcpy (dst, s1);
- if (strncat (dst, "foo", 100) != dst || strcmp (dst, "hello worldfoo"))
- abort ();
- strcpy (dst, s1);
- if (strncat (dst, s1, 100) != dst || strcmp (dst, "hello worldhello world"))
- abort ();
- if (chk_calls != 3)
- abort ();
-
chk_calls = 0;
/* The following calls have side-effects in dest, so are not checked. */
strcpy (dst, s1); d2 = dst;
--
2.45.0