https://gcc.gnu.org/g:4c80802457353f945bc1673975be4403aa78d2bd

commit 4c80802457353f945bc1673975be4403aa78d2bd
Author: Tobias Burnus <tbur...@baylibre.com>
Date:   Mon Jan 27 12:51:06 2025 +0100

    Fortran: Create fresh ts.u.cl for result in gfc_get_symbol_for_expr 
[PR118441]
    
    For intrinsic routines, called in libraries, the prototype is created from
    the call via gfc_get_symbol_for_expr. For the actual arguments, it calls
    gfc_copy_formal_args_intr which already ensures that the ts.u.cl is freshly
    allocated.
    
    This commit now ensures the same for character-returning functions.
    
            PR fortran/118441
    
    gcc/fortran/ChangeLog:
    
            * trans-intrinsic.cc (gfc_get_symbol_for_expr): Use
            gfc_new_charlen for character-returning functions.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/gomp/intrinsic_pack_7.f90: New test.
    
    (cherry picked from commit c5a8e22c5dacf4f9d4f66e60990bf34c70f04714)

Diff:
---
 gcc/fortran/ChangeLog.omp                           | 9 +++++++++
 gcc/fortran/trans-intrinsic.cc                      | 2 ++
 gcc/testsuite/ChangeLog.omp                         | 8 ++++++++
 gcc/testsuite/gfortran.dg/gomp/intrinsic_pack_7.f90 | 9 +++++++++
 4 files changed, 28 insertions(+)

diff --git a/gcc/fortran/ChangeLog.omp b/gcc/fortran/ChangeLog.omp
index c6652f0a9734..22fab76096f9 100644
--- a/gcc/fortran/ChangeLog.omp
+++ b/gcc/fortran/ChangeLog.omp
@@ -1,3 +1,12 @@
+2025-01-27  Tobias Burnus  <tbur...@baylibre.com>
+
+       Backported from master:
+       2025-01-16  Tobias Burnus  <tbur...@baylibre.com>
+
+       PR fortran/118441
+       * trans-intrinsic.cc (gfc_get_symbol_for_expr): Use
+       gfc_new_charlen for character-returning functions.
+
 2025-01-27  Tobias Burnus  <tbur...@baylibre.com>
 
        Backported from master:
diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index f15b7e5e726b..4c8a898b9f48 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -4206,6 +4206,8 @@ gfc_get_symbol_for_expr (gfc_expr * expr, bool 
ignore_optional)
   sym = gfc_new_symbol (expr->value.function.name, NULL);
 
   sym->ts = expr->ts;
+  if (sym->ts.type == BT_CHARACTER)
+    sym->ts.u.cl = gfc_new_charlen (gfc_current_ns, NULL);
   sym->attr.external = 1;
   sym->attr.function = 1;
   sym->attr.always_explicit = 1;
diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp
index ed535301dd09..2beb177849bd 100644
--- a/gcc/testsuite/ChangeLog.omp
+++ b/gcc/testsuite/ChangeLog.omp
@@ -1,3 +1,11 @@
+2025-01-27  Tobias Burnus  <tbur...@baylibre.com>
+
+       Backported from master:
+       2025-01-16  Tobias Burnus  <tbur...@baylibre.com>
+
+       PR fortran/118441
+       * gfortran.dg/gomp/intrinsic_pack_7.f90: New test.
+
 2025-01-27  Tobias Burnus  <tbur...@baylibre.com>
 
        Backported from master:
diff --git a/gcc/testsuite/gfortran.dg/gomp/intrinsic_pack_7.f90 
b/gcc/testsuite/gfortran.dg/gomp/intrinsic_pack_7.f90
new file mode 100644
index 000000000000..576a89940922
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/gomp/intrinsic_pack_7.f90
@@ -0,0 +1,9 @@
+! PR fortran/118441
+
+subroutine sub(s)
+  character(len=*), intent(inout) :: s(:)
+  integer :: n
+  s( : ) =       s(:)                     ! OK
+  n      = count(s(:) /= '')
+  s(1:n) = pack (s(:), mask=(s(:) /= '')) ! ICE
+end subroutine sub

Reply via email to