[gcc r16-9314] testsuite: skip test for targets that can deref null [PR126261]
Torbjorn Svensson
azoff@gcc.gnu.org
Mon Jul 20 13:45:39 GMT 2026
https://gcc.gnu.org/g:307954e9c03aba314d6050d36edc056887df9a5d
commit r16-9314-g307954e9c03aba314d6050d36edc056887df9a5d
Author: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
Date: Tue Jul 14 16:38:10 2026 +0200
testsuite: skip test for targets that can deref null [PR126261]
As arm-none-eabi targets might have readable memory at address 0,
g++.dg/torture/pr101373.C test will "work" on some targets, while others
might tigger a fault. To avoid the ambiguity, lets skip the test if
target allows null to be dereferenced.
PR testsuite/126261
gcc/ChangeLog:
* doc/sourcebuild.texi (can_deref_null): Document.
gcc/testsuite/ChangeLog:
* g++.dg/torture/pr101373.C: Use effective-target can_deref_null.
* lib/target-supports.exp (check_effective_target_can_deref_null):
New proc.
Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
(cherry picked from commit 2e26607f7f14bd32ea8082ee626f207d6a9f87a0)
Diff:
---
gcc/doc/sourcebuild.texi | 4 ++++
gcc/testsuite/g++.dg/torture/pr101373.C | 1 +
gcc/testsuite/lib/target-supports.exp | 20 ++++++++++++++++++++
3 files changed, 25 insertions(+)
diff --git a/gcc/doc/sourcebuild.texi b/gcc/doc/sourcebuild.texi
index cea1fd3872f5..069fd3892a7d 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2723,6 +2723,10 @@ Target supports the execution of @code{amx-tf32} instructions.
@item amx_fp8
Target supports the execution of @code{amx-fp8} instructions.
+@item can_deref_null
+Target runtime permits dereferencing a null pointer without trapping, for
+example because address zero is mapped and readable.
+
@item cell_hw
Test system can execute AltiVec and Cell PPU instructions.
diff --git a/gcc/testsuite/g++.dg/torture/pr101373.C b/gcc/testsuite/g++.dg/torture/pr101373.C
index f8c809739e2d..45f1e455eec3 100644
--- a/gcc/testsuite/g++.dg/torture/pr101373.C
+++ b/gcc/testsuite/g++.dg/torture/pr101373.C
@@ -1,5 +1,6 @@
// { dg-do run }
// { dg-xfail-run-if "PR100409" { *-*-* } }
+// { dg-skip-if "PR126261" { can_deref_null } }
int __attribute__((const,noipa)) foo (int j)
{
diff --git a/gcc/testsuite/lib/target-supports.exp b/gcc/testsuite/lib/target-supports.exp
index 4037ffe9319b..773ea3af570d 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -15027,3 +15027,23 @@ proc check_effective_target_memtag_exec {} {
}
return 1;
}
+
+# Return 1 if the target runtime can deref null, 0 otherwise.
+# Cache the result.
+
+proc check_effective_target_can_deref_null { } {
+ return [check_runtime can_deref_null {
+ char __attribute__((noipa))
+ read_mem (volatile char *p)
+ {
+ return *p;
+ }
+
+ int
+ main ()
+ {
+ read_mem (0);
+ return 0;
+ }
+ } "-O0 -fno-delete-null-pointer-checks -Wno-null-dereference"]
+}
More information about the Gcc-cvs
mailing list