[gcc r15-11398] testsuite: skip test for targets that can deref null [PR126261]

Torbjorn Svensson via Gcc-cvs <[email protected]>
Newsgroups gmane.comp.gcc.cvs
Message-ID <[email protected]>
https://gcc.gnu.org/g:cf69dd0145e174e5497739a373100f83be1894f6

commit r15-11398-gcf69dd0145e174e5497739a373100f83be1894f6
Author: Torbjörn SVENSSON <[email protected]>
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 <[email protected]>
    (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 d27d1e3aeca7..0bb455b5929b 100644
--- a/gcc/doc/sourcebuild.texi
+++ b/gcc/doc/sourcebuild.texi
@@ -2717,6 +2717,10 @@ Target supports the execution of @code{amx-transpose} 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 e27b0f5e32bf..d91c8378d01e 100644
--- a/gcc/testsuite/lib/target-supports.exp
+++ b/gcc/testsuite/lib/target-supports.exp
@@ -14547,3 +14547,23 @@ proc check_effective_target_valgrind { } {
     }
     return 0
 }
+
+# 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"]
+}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.