https://gcc.gnu.org/g:09dd47bc383f30f1ba03ec80f8bd849eb6283d29

commit r15-6399-g09dd47bc383f30f1ba03ec80f8bd849eb6283d29
Author: Alexandre Oliva <ol...@adacore.com>
Date:   Fri Dec 20 18:02:01 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 29ba143b4620..6b3f5b078f29 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..6c24cad65296
--- /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