https://gcc.gnu.org/g:2e26607f7f14bd32ea8082ee626f207d6a9f87a0
commit r17-2559-g2e26607f7f14bd32ea8082ee626f207d6a9f87a0 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]> 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 87dc9b5637dd..e53c0b372103 100644 --- a/gcc/doc/sourcebuild.texi +++ b/gcc/doc/sourcebuild.texi @@ -2743,6 +2743,10 @@ Target supports the execution of @code{amx-movrs} 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 4e17b61fdb66..de98aeb27313 100644 --- a/gcc/testsuite/lib/target-supports.exp +++ b/gcc/testsuite/lib/target-supports.exp @@ -15168,3 +15168,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"] +}
