https://gcc.gnu.org/g:e2aa76c2ba070bd5864e3d67729b735b8ad0e80a

commit e2aa76c2ba070bd5864e3d67729b735b8ad0e80a
Author: Alexandre Oliva <ol...@adacore.com>
Date:   Wed Dec 18 14:47:07 2024 -0300

    strub: accept indirection of volatile pointer types [PR118007]
    
    We don't want to indirect pointers in strub wrappers, because it
    generally isn't profitable, but if the argument is volatile, then we
    must use indirection to preserve access patterns, so amend the
    assertion check.
    
    
    for  gcc/ChangeLog
    
            PR middle-end/118007
            * ipa-strub.cc (pass_ipa_strub::execute): Accept indirecting
            volatile args of pointer types.
    
    for  gcc/testsuite/ChangeLog
    
            PR middle-end/118007
            * gcc.dg/strub-pr118007.c: New.

Diff:
---
 gcc/ipa-strub.cc                      | 13 +++++++------
 gcc/testsuite/gcc.dg/strub-pr118007.c |  5 +++++
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/gcc/ipa-strub.cc b/gcc/ipa-strub.cc
index f6e09cd50b6d..6d4a7eac36f4 100644
--- a/gcc/ipa-strub.cc
+++ b/gcc/ipa-strub.cc
@@ -2881,12 +2881,13 @@ pass_ipa_strub::execute (function *)
                   && (tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (nparm)))
                       <= 4 * UNITS_PER_WORD))))
        {
-         /* No point in indirecting pointer types.  Presumably they
-            won't ever pass the size-based test above, but check the
-            assumption here, because getting this wrong would mess
-            with attribute access and possibly others.  We deal with
-            fn spec below.  */
-         gcc_checking_assert (!POINTER_TYPE_P (TREE_TYPE (nparm)));
+         /* No point in indirecting pointer types, unless they're
+            volatile.  Presumably they won't ever pass the size-based
+            test above, but check the assumption here, because
+            getting this wrong would mess with attribute access and
+            possibly others.  We deal with fn spec below.  */
+         gcc_checking_assert (!POINTER_TYPE_P (TREE_TYPE (nparm))
+                              || TREE_THIS_VOLATILE (parm));
 
          indirect_nparms.add (nparm);
 
diff --git a/gcc/testsuite/gcc.dg/strub-pr118007.c 
b/gcc/testsuite/gcc.dg/strub-pr118007.c
new file mode 100644
index 000000000000..f5ab59ea9aeb
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/strub-pr118007.c
@@ -0,0 +1,5 @@
+/* { dg-require-effective-target strub } */
+/* { dg-do compile } */
+/* { dg-options "-fstrub-all -O2" } */
+
+void rb_ec_error_print(struct rb_execution_context_struct *volatile) {}

Reply via email to