[gcc r14-11805] Fortran: default-initialization and functions returning derived type [PR85750]

2025-05-25 Thread Harald Anlauf via Gcc-cvs
https://gcc.gnu.org/g:0100ea2b4eb1c83972e0db07503a7cfe8a38932e

commit r14-11805-g0100ea2b4eb1c83972e0db07503a7cfe8a38932e
Author: Harald Anlauf 
Date:   Thu May 15 21:07:07 2025 +0200

Fortran: default-initialization and functions returning derived type 
[PR85750]

Functions with non-pointer, non-allocatable result and of derived type did
not always get initialized although the type had default-initialization,
and a derived type component had the allocatable or pointer attribute.
Rearrange the logic when to apply default-initialization.

PR fortran/85750

gcc/fortran/ChangeLog:

* resolve.cc (resolve_symbol): Reorder conditions when to apply
default-initializers.

gcc/testsuite/ChangeLog:

* gfortran.dg/alloc_comp_auto_array_3.f90: Adjust scan counts.
* gfortran.dg/alloc_comp_class_3.f03: Remove bogus warnings.
* gfortran.dg/alloc_comp_class_4.f03: Likewise.
* gfortran.dg/allocate_with_source_14.f03: Adjust scan count.
* gfortran.dg/derived_constructor_comps_6.f90: Likewise.
* gfortran.dg/derived_result_5.f90: New test.

(cherry picked from commit d31ab498b12ebbe4f50acb2aa240ff92c73f310c)

Diff:
---
 gcc/fortran/resolve.cc |   7 +-
 .../gfortran.dg/alloc_comp_auto_array_3.f90|   4 +-
 gcc/testsuite/gfortran.dg/alloc_comp_class_3.f03   |   3 +-
 gcc/testsuite/gfortran.dg/alloc_comp_class_4.f03   |   5 +-
 .../gfortran.dg/allocate_with_source_14.f03|   2 +-
 .../gfortran.dg/derived_constructor_comps_6.f90|   2 +-
 gcc/testsuite/gfortran.dg/derived_result_5.f90 | 123 +
 7 files changed, 134 insertions(+), 12 deletions(-)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 4d8484a36f12..10a9e58b287a 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -17134,15 +17134,16 @@ skip_interfaces:
  || (a->dummy && !a->pointer && a->intent == INTENT_OUT
  && sym->ns->proc_name->attr.if_source != IFSRC_IFBODY))
apply_default_init (sym);
+  else if (a->function && !a->pointer && !a->allocatable && !a->use_assoc
+  && sym->result)
+   /* Default initialization for function results.  */
+   apply_default_init (sym->result);
   else if (a->function && sym->result && a->access != ACCESS_PRIVATE
   && (sym->ts.u.derived->attr.alloc_comp
   || sym->ts.u.derived->attr.pointer_comp))
/* Mark the result symbol to be referenced, when it has allocatable
   components.  */
sym->result->attr.referenced = 1;
-  else if (a->function && !a->pointer && !a->allocatable && sym->result)
-   /* Default initialization for function results.  */
-   apply_default_init (sym->result);
 }
 
   if (sym->ts.type == BT_CLASS && sym->ns == gfc_current_ns
diff --git a/gcc/testsuite/gfortran.dg/alloc_comp_auto_array_3.f90 
b/gcc/testsuite/gfortran.dg/alloc_comp_auto_array_3.f90
index 2af089e84e8d..d0751f3d3eba 100644
--- a/gcc/testsuite/gfortran.dg/alloc_comp_auto_array_3.f90
+++ b/gcc/testsuite/gfortran.dg/alloc_comp_auto_array_3.f90
@@ -25,6 +25,6 @@ contains
 allocate (array(1)%bigarr)
   end function
 end
-! { dg-final { scan-tree-dump-times "builtin_malloc" 3 "original" } }
+! { dg-final { scan-tree-dump-times "builtin_malloc" 4 "original" } }
 ! { dg-final { scan-tree-dump-times "builtin_free" 3 "original" } }
-! { dg-final { scan-tree-dump-times "while \\(1\\)" 4 "original" } }
+! { dg-final { scan-tree-dump-times "while \\(1\\)" 5 "original" } }
diff --git a/gcc/testsuite/gfortran.dg/alloc_comp_class_3.f03 
b/gcc/testsuite/gfortran.dg/alloc_comp_class_3.f03
index 0753e33d535d..8202d783621c 100644
--- a/gcc/testsuite/gfortran.dg/alloc_comp_class_3.f03
+++ b/gcc/testsuite/gfortran.dg/alloc_comp_class_3.f03
@@ -45,11 +45,10 @@ contains
 type(c), value :: d
   end subroutine
 
-  type(c) function c_init()  ! { dg-warning "not set" }
+  type(c) function c_init()
   end function
 
   subroutine sub(d)
 type(u), value :: d
   end subroutine
 end program test_pr58586
-
diff --git a/gcc/testsuite/gfortran.dg/alloc_comp_class_4.f03 
b/gcc/testsuite/gfortran.dg/alloc_comp_class_4.f03
index 4a55d73b245e..9ff38e3fb7c5 100644
--- a/gcc/testsuite/gfortran.dg/alloc_comp_class_4.f03
+++ b/gcc/testsuite/gfortran.dg/alloc_comp_class_4.f03
@@ -51,14 +51,14 @@ contains
 type(t), value :: d
   end subroutine
 
-  type(c) function c_init() ! { dg-warning "not set" }
+  type(c) function c_init()
   end function
 
   class(c) function c_init2() ! { dg-warning "not set" }
 allocatable :: c_init2
   end function
 
-  type(c) function d_init(this) ! { dg-warning "not set" }
+  type(c) function d_init(this)
 class(d) :: this
   end function
 
@@ -102,4 +102,3 @@ program test_pr58586
   call add_c(oe%init())
   deallocate(oe)
 end program
-
diff --git a/gcc/tes

[gcc r14-11804] Fortran: default-initialization of derived-type function results [PR98454]

2025-05-25 Thread Harald Anlauf via Gcc-cvs
https://gcc.gnu.org/g:9c21d7eaf8383749d1a9cd266709ec9ed04e3a00

commit r14-11804-g9c21d7eaf8383749d1a9cd266709ec9ed04e3a00
Author: Harald Anlauf 
Date:   Thu Aug 29 22:17:07 2024 +0200

Fortran: default-initialization of derived-type function results [PR98454]

gcc/fortran/ChangeLog:

PR fortran/98454
* resolve.cc (resolve_symbol): Add default-initialization of
non-allocatable, non-pointer derived-type function results.

gcc/testsuite/ChangeLog:

PR fortran/98454
* gfortran.dg/alloc_comp_class_4.f03: Remove bogus pattern.
* gfortran.dg/pdt_26.f03: Adjust expected count.
* gfortran.dg/derived_result_3.f90: New test.

(cherry picked from commit b222122d4e93de2238041a01b1886c7dfd9944da)

Diff:
---
 gcc/fortran/resolve.cc   |   3 +
 gcc/testsuite/gfortran.dg/alloc_comp_class_4.f03 |   2 +-
 gcc/testsuite/gfortran.dg/derived_result_3.f90   | 158 +++
 gcc/testsuite/gfortran.dg/pdt_26.f03 |   2 +-
 4 files changed, 163 insertions(+), 2 deletions(-)

diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc
index 4f4decd1bc39..4d8484a36f12 100644
--- a/gcc/fortran/resolve.cc
+++ b/gcc/fortran/resolve.cc
@@ -17140,6 +17140,9 @@ skip_interfaces:
/* Mark the result symbol to be referenced, when it has allocatable
   components.  */
sym->result->attr.referenced = 1;
+  else if (a->function && !a->pointer && !a->allocatable && sym->result)
+   /* Default initialization for function results.  */
+   apply_default_init (sym->result);
 }
 
   if (sym->ts.type == BT_CLASS && sym->ns == gfc_current_ns
diff --git a/gcc/testsuite/gfortran.dg/alloc_comp_class_4.f03 
b/gcc/testsuite/gfortran.dg/alloc_comp_class_4.f03
index 3118b552a301..4a55d73b245e 100644
--- a/gcc/testsuite/gfortran.dg/alloc_comp_class_4.f03
+++ b/gcc/testsuite/gfortran.dg/alloc_comp_class_4.f03
@@ -71,7 +71,7 @@ contains
 allocatable :: t_init
   end function
 
-  type(t) function static_t_init() ! { dg-warning "not set" }
+  type(t) function static_t_init()
   end function
 end module test_pr58586_mod
 
diff --git a/gcc/testsuite/gfortran.dg/derived_result_3.f90 
b/gcc/testsuite/gfortran.dg/derived_result_3.f90
new file mode 100644
index ..4b28f7e28c92
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/derived_result_3.f90
@@ -0,0 +1,158 @@
+! { dg-do run }
+! PR fortran/98454 - default-initialization of derived-type function results
+
+program test
+  implicit none
+  type t
+ integer :: unit = -1
+  end type t
+  type u
+ integer, allocatable :: unit(:)
+  end type u
+  type(t) :: x, x3(3)
+  type(u) :: y, y4(4)
+
+  ! Scalar function result, DT with default initializer
+  x = t(42)
+  if (x% unit /= 42) stop 1
+  x = g()
+  if (x% unit /= -1) stop 2
+  x = t(42)
+  x = f()
+  if (x% unit /= -1) stop 3
+  x = t(42)
+  x = h()
+  if (x% unit /= -1) stop 4
+  x = t(42)
+  x = k()
+  if (x% unit /= -1) stop 5
+
+  ! Array function result, DT with default initializer
+  x3 = t(13)
+  if (any (x3% unit /= 13)) stop 11
+  x3 = f3()
+  if (any (x3% unit /= -1)) stop 12
+  x3 = t(13)
+  x3 = g3()
+  if (any (x3% unit /= -1)) stop 13
+  x3 = t(13)
+  x3 = h3()
+  if (any (x3% unit /= -1)) stop 14
+  x3 = t(13)
+  x3 = k3()
+  if (any (x3% unit /= -1)) stop 15
+
+  ! Scalar function result, DT with allocatable component
+  y = u()
+  if (allocated (y% unit)) stop 21
+  allocate (y% unit(42))
+  y = m()
+  if (allocated (y% unit)) stop 22
+  allocate (y% unit(42))
+  y = n()
+  if (allocated (y% unit)) stop 23
+  allocate (y% unit(42))
+  y = o()
+  if (allocated (y% unit)) stop 24
+  allocate (y% unit(42))
+  y = p()
+  if (allocated (y% unit)) stop 25
+
+  ! Array function result, DT with allocatable component
+  y4 = u()
+  if (allocated (y4(1)% unit)) stop 31
+  allocate (y4(1)% unit(42))
+  y4 = m4()
+  if (allocated (y4(1)% unit)) stop 32
+  y4 = u()
+  allocate (y4(1)% unit(42))
+  y4 = n4()
+  if (allocated (y4(1)% unit)) stop 33
+
+  y4 = u()
+  allocate (y4(1)% unit(42))
+  y4 = o4()
+  if (allocated (y4(1)% unit)) stop 34
+  y4 = u()
+  allocate (y4(1)% unit(42))
+  y4 = p4()
+  if (allocated (y4(1)% unit)) stop 35
+
+contains
+
+  ! Function result not referenced within function body
+  function f()
+type(t) :: f
+  end function f
+
+  function k() result (f)
+type(t) :: f
+  end function k
+
+  ! Function result referenced within function body
+  function g()
+type(t) :: g
+if (g% unit /= -1) stop 41
+  end function g
+
+  function h() result (g)
+type(t) :: g
+if (g% unit /= -1) stop 42
+  end function h
+
+  ! Function result not referenced within function body
+  function f3 ()
+type(t) :: f3(3)
+  end function f3
+
+  function k3() result (f3)
+type(t) :: f3(3)
+  end function k3
+
+  ! Function result referenced within function body
+  function g3()
+type(t) :: g3(3)
+if (any

[gcc r16-874] rs6000: Remove include of reload.h

2025-05-25 Thread Segher Boessenkool via Gcc-cvs
https://gcc.gnu.org/g:f9e63ebcf60964fdc3b84c9b7fd7f19a9bf35b04

commit r16-874-gf9e63ebcf60964fdc3b84c9b7fd7f19a9bf35b04
Author: Segher Boessenkool 
Date:   Tue May 20 22:01:30 2025 +

rs6000: Remove include of reload.h

As one of the last steps in removing old reload, I'll delete the reload.h
header file.  It would be a bit embarrassing if that stopped the target I am
responsible for from working, so let's prevent that.

We do not actually use anything from this header file (checked by building
with this patch, and make check has identical results as well), so it was
easy for our port.  Many other ports will be like this, but some will need
some adjustments.  I'll do cross builds of many ports before it is all over,
but it would be good if other ports tried to remove reload.h from their
includes as well :-)

2025-06-26  Segher Boessenkool  

* config/rs6000/rs6000.cc: Remove include of reload.h .

Diff:
---
 gcc/config/rs6000/rs6000.cc | 1 -
 1 file changed, 1 deletion(-)

diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index 7ea377781034..7375c36e406d 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -55,7 +55,6 @@
 #include "output.h"
 #include "common/common-target.h"
 #include "langhooks.h"
-#include "reload.h"
 #include "sched-int.h"
 #include "gimplify.h"
 #include "gimple-iterator.h"


[gcc r15-9727] MicroBlaze does not support speculative execution (CVE-2017-5753)

2025-05-25 Thread Michael Eager via Gcc-cvs
https://gcc.gnu.org/g:4ac1fb51c7b780159837e951bd893954d7d8803a

commit r15-9727-g4ac1fb51c7b780159837e951bd893954d7d8803a
Author: Michael J. Eager 
Date:   Sun May 25 09:25:27 2025 -0700

MicroBlaze does not support speculative execution (CVE-2017-5753)

gcc/
PR target/86772
Tracking CVE-2017-5753
* config/microblaze/microblaze.cc 
(TARGET_HAVE_SPECULATION_SAFE_VALUE):
Define to speculation_save_value_not_needed

Diff:
---
 gcc/config/microblaze/microblaze.cc | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/config/microblaze/microblaze.cc 
b/gcc/config/microblaze/microblaze.cc
index fc223fb08e11..4b7f0a1a5e0f 100644
--- a/gcc/config/microblaze/microblaze.cc
+++ b/gcc/config/microblaze/microblaze.cc
@@ -239,6 +239,10 @@ section *sdata2_section;
 #define TARGET_HAVE_TLS true
 #endif
 
+/* MicroBlaze does not do speculative execution.  */
+#undef  TARGET_HAVE_SPECULATION_SAFE_VALUE
+#define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed
+
 /* Return truth value if a CONST_DOUBLE is ok to be a legitimate constant.  */
 static bool
 microblaze_const_double_ok (rtx op, machine_mode mode)


[gcc r16-871] MicroBlaze does not support speculative execution (CVE-2017-5753)

2025-05-25 Thread Michael Eager via Gcc-cvs
https://gcc.gnu.org/g:2159f024f63c12fd356748ae8fc106bb9b355688

commit r16-871-g2159f024f63c12fd356748ae8fc106bb9b355688
Author: Michael J. Eager 
Date:   Sun May 25 07:12:14 2025 -0700

MicroBlaze does not support speculative execution (CVE-2017-5753)

gcc/
PR target/86772
Tracking CVE-2017-5753
* config/microblaze/microblaze.cc 
(TARGET_HAVE_SPECULATION_SAFE_VALUE):
Define to speculation_save_value_not_needed

Diff:
---
 gcc/config/microblaze/microblaze.cc | 4 
 1 file changed, 4 insertions(+)

diff --git a/gcc/config/microblaze/microblaze.cc 
b/gcc/config/microblaze/microblaze.cc
index db8e33465a83..2ab5ada4ec9e 100644
--- a/gcc/config/microblaze/microblaze.cc
+++ b/gcc/config/microblaze/microblaze.cc
@@ -239,6 +239,10 @@ section *sdata2_section;
 #define TARGET_HAVE_TLS true
 #endif
 
+/* MicroBlaze does not do speculative execution.  */
+#undef  TARGET_HAVE_SPECULATION_SAFE_VALUE
+#define TARGET_HAVE_SPECULATION_SAFE_VALUE speculation_safe_value_not_needed
+
 /* Return truth value if a CONST_DOUBLE is ok to be a legitimate constant.  */
 static bool
 microblaze_const_double_ok (rtx op, machine_mode mode)


[gcc r16-870] c++: dump_template_bindings tweak

2025-05-25 Thread Jason Merrill via Gcc-cvs
https://gcc.gnu.org/g:9b8caae8d189c5bd7de502844b17341a7a6dddc5

commit r16-870-g9b8caae8d189c5bd7de502844b17341a7a6dddc5
Author: Jason Merrill 
Date:   Thu May 22 17:11:50 2025 -0400

c++: dump_template_bindings tweak

in r12-1100 we stopped printing template bindings like T = T.  The check for
this relied on TREE_CHAIN of a TEMPLATE_TYPE_PARM holding the declaration of
that type-parameter.  This should be written as TYPE_STUB_DECL.  In
addition, TYPE_STUB_DECL is only set on the TYPE_MAIN_VARIANT, so we need to
check that as well.  Which is also desirable because volatile T is visibly
distinct from T.

gcc/cp/ChangeLog:

* error.cc (dump_template_bindings): Correct skipping of
redundant bindings.

Diff:
---
 gcc/cp/error.cc | 13 +++--
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc
index 75bf7dcef62d..305064d476c4 100644
--- a/gcc/cp/error.cc
+++ b/gcc/cp/error.cc
@@ -541,12 +541,13 @@ dump_template_bindings (cxx_pretty_printer *pp, tree 
parms, tree args,
  /* If the template argument repeats the template parameter (T = T),
 skip the parameter.*/
  if (arg && TREE_CODE (arg) == TEMPLATE_TYPE_PARM
-   && TREE_CODE (parm_i) == TREE_LIST
-   && TREE_CODE (TREE_VALUE (parm_i)) == TYPE_DECL
-   && TREE_CODE (TREE_TYPE (TREE_VALUE (parm_i)))
-== TEMPLATE_TYPE_PARM
-   && DECL_NAME (TREE_VALUE (parm_i))
-== DECL_NAME (TREE_CHAIN (arg)))
+ && arg == TYPE_MAIN_VARIANT (arg)
+ && TREE_CODE (parm_i) == TREE_LIST
+ && TREE_CODE (TREE_VALUE (parm_i)) == TYPE_DECL
+ && (TREE_CODE (TREE_TYPE (TREE_VALUE (parm_i)))
+ == TEMPLATE_TYPE_PARM)
+ && (DECL_NAME (TREE_VALUE (parm_i))
+ == DECL_NAME (TYPE_STUB_DECL (arg
continue;
 
  semicolon_or_introducer ();


[gcc r16-873] [AUTOFDO] Enable ipa-split for auto-profile

2025-05-25 Thread Kugan Vivekanandarajah via Gcc-cvs
https://gcc.gnu.org/g:53fb5a1a98a2d72ada7786f28e94a724916a39b1

commit r16-873-g53fb5a1a98a2d72ada7786f28e94a724916a39b1
Author: Kugan Vivekanandarajah 
Date:   Mon May 26 10:52:45 2025 +1000

[AUTOFDO] Enable ipa-split for auto-profile

ipa-split is not now run for auto-profile. IMO this was an oversight.
This patch enables it similar to PGO runs.

gcc/ChangeLog:

* ipa-split.cc (pass_feedback_split_functions::clone): New.
* passes.def: Enable pass_feedback_split_functions for
pass_ipa_auto_profile.

Signed-off-by: Kugan Vivekanandarajah 

Diff:
---
 gcc/ipa-split.cc | 4 
 gcc/passes.def   | 3 +++
 2 files changed, 7 insertions(+)

diff --git a/gcc/ipa-split.cc b/gcc/ipa-split.cc
index 729fb79af52c..933ca16c9469 100644
--- a/gcc/ipa-split.cc
+++ b/gcc/ipa-split.cc
@@ -1992,6 +1992,10 @@ public:
   return execute_feedback_split_functions ();
 }
 
+  opt_pass * clone () final override
+  {
+return new pass_feedback_split_functions (m_ctxt);
+  }
 }; // class pass_feedback_split_functions
 
 bool
diff --git a/gcc/passes.def b/gcc/passes.def
index 3b251052e53a..0f7a65926990 100644
--- a/gcc/passes.def
+++ b/gcc/passes.def
@@ -140,6 +140,9 @@ along with GCC; see the file COPYING3.  If not see
 
   NEXT_PASS (pass_target_clone);
   NEXT_PASS (pass_ipa_auto_profile);
+  PUSH_INSERT_PASSES_WITHIN (pass_ipa_auto_profile)
+  NEXT_PASS (pass_feedback_split_functions);
+  POP_INSERT_PASSES ()
   NEXT_PASS (pass_ipa_tree_profile);
   PUSH_INSERT_PASSES_WITHIN (pass_ipa_tree_profile)
   NEXT_PASS (pass_feedback_split_functions);


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Correction régression gomp/pr94672

2025-05-25 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:de9ad798184223252248eef64352f22cd4a0a4e4

commit de9ad798184223252248eef64352f22cd4a0a4e4
Author: Mikael Morin 
Date:   Sat May 24 23:19:56 2025 +0200

Correction régression gomp/pr94672

Diff:
---
 gcc/fortran/trans-array.cc  | 16 ++
 gcc/fortran/trans-decl.cc   | 48 +++---
 gcc/fortran/trans-descriptor.cc |  3 +-
 gcc/fortran/trans-expr.cc   |  8 +++--
 gcc/fortran/trans-intrinsic.cc  |  3 +-
 gcc/fortran/trans-stmt.cc   |  3 +-
 gcc/fortran/trans-types.cc  | 65 +
 gcc/fortran/trans-types.h   |  4 +--
 gcc/stor-layout.cc  | 10 +--
 9 files changed, 122 insertions(+), 38 deletions(-)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 43e5e1e756bc..264abd407b46 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -1058,7 +1058,9 @@ gfc_trans_create_temp_array (stmtblock_t * pre, 
stmtblock_t * post, gfc_ss * ss,
 }
   type =
 gfc_get_array_type_bounds (eltype, total_dim, 0, from, to, 1,
-  GFC_ARRAY_UNKNOWN, true);
+  GFC_ARRAY_UNKNOWN, true,
+  ss->info->expr ? ss->info->expr->ts.type
+ : BT_UNKNOWN);
   /* Restore the upper bound, for the rest (not type-related) of the descriptor
  initialization.  */
   if (to0)
@@ -2169,7 +2171,8 @@ gfc_build_constant_array_constructor (gfc_expr * expr, 
tree type)
NULL, tmp - 1);
   }
 
-  tmptype = gfc_get_nodesc_array_type (type, &as, PACKED_STATIC, true);
+  tmptype = gfc_get_nodesc_array_type (type, &as, PACKED_STATIC, true,
+  expr->ts.type);
 
   /* as is not needed anymore.  */
   for (i = 0; i < as.rank + as.corank; i++)
@@ -7782,7 +7785,8 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
 
  parmtype = gfc_get_array_type_bounds (parmtype, loop.dimen, codim,
loop.from, loop.to, 0,
-   GFC_ARRAY_UNKNOWN, false);
+   GFC_ARRAY_UNKNOWN, false,
+   expr->ts.type);
  parm = gfc_create_var (parmtype, "parm");
 
  /* When expression is a class object, then add the class' handle to
@@ -9157,7 +9161,8 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl, 
tree dest,
{
  cdesc = gfc_get_array_type_bounds (tmp, 1, 0, &gfc_index_one_node,
 &ubound, 1,
-GFC_ARRAY_ALLOCATABLE, false);
+GFC_ARRAY_ALLOCATABLE, false,
+c->ts.type);
 
  cdesc = gfc_create_var (cdesc, "cdesc");
  DECL_ARTIFICIAL (cdesc) = 1;
@@ -9310,7 +9315,8 @@ structure_alloc_comps (gfc_symbol * der_type, tree decl, 
tree dest,
 
  cdesc = gfc_get_array_type_bounds (tmp, 1, 0, &gfc_index_one_node,
 &ubound, 1,
-GFC_ARRAY_ALLOCATABLE, false);
+GFC_ARRAY_ALLOCATABLE, false,
+c->ts.type);
 
  cdesc = gfc_create_var (cdesc, "cdesc");
  DECL_ARTIFICIAL (cdesc) = 1;
diff --git a/gcc/fortran/trans-decl.cc b/gcc/fortran/trans-decl.cc
index 7fcb50fcb685..aae0c26ab8fd 100644
--- a/gcc/fortran/trans-decl.cc
+++ b/gcc/fortran/trans-decl.cc
@@ -1260,7 +1260,7 @@ gfc_build_qualified_array (tree decl, gfc_symbol * sym)
 
   if (! COMPLETE_TYPE_P (type)
   && GFC_TYPE_ARRAY_SIZE (type)
-  && GFC_TYPE_PACKED_ARRAY (type))
+  && GFC_TYPE_ARRAY_ELEM_LEN (type))
 {
   tree size, range;
 
@@ -1274,7 +1274,47 @@ gfc_build_qualified_array (tree decl, gfc_symbol * sym)
  size, lower);
   range = build_range_type (gfc_array_index_type, lower, size);
   TYPE_DOMAIN (type) = range;
-  layout_type (type);
+  if (GFC_TYPE_PACKED_ARRAY (type))
+   layout_type (type);
+  else
+   {
+ tree off = gfc_index_zero_node;
+ for (dim = 0; dim < GFC_TYPE_ARRAY_RANK (type); dim++)
+   {
+ tree lb = GFC_TYPE_ARRAY_LBOUND (type, dim);
+ tree ub = GFC_TYPE_ARRAY_UBOUND (type, dim);
+ tree extent = gfc_conv_array_extent_dim (lb, ub, nullptr);
+ tree extent_m1 = fold_build2_loc (input_location, MINUS_EXPR,
+   gfc_array_index_type, extent,
+   gfc_index_one_node);
+ tree spacing = GFC_TYPE_ARRAY_SPACING (type, dim);
+ tree tmp = 

[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Mise à jour motif dump gomp/affinity-clause-1

2025-05-25 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:251490a66837a343bb289ff5d3c1a2b209e19af3

commit 251490a66837a343bb289ff5d3c1a2b209e19af3
Author: Mikael Morin 
Date:   Sat May 24 13:43:51 2025 +0200

Mise à jour motif dump gomp/affinity-clause-1

Diff:
---
 gcc/testsuite/gfortran.dg/gomp/affinity-clause-1.f90 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/gcc/testsuite/gfortran.dg/gomp/affinity-clause-1.f90 
b/gcc/testsuite/gfortran.dg/gomp/affinity-clause-1.f90
index 32c9acef070e..1ccc3e00afc2 100644
--- a/gcc/testsuite/gfortran.dg/gomp/affinity-clause-1.f90
+++ b/gcc/testsuite/gfortran.dg/gomp/affinity-clause-1.f90
@@ -22,11 +22,11 @@ end
 
 ! { dg-final { scan-tree-dump-times "D\\.\[0-9\]+ = .integer.kind=4.. 
__builtin_cosf ..real.kind=4.. a \\+ 1.0e\\+0\\);" 2 "original" } }
 
-! { dg-final { scan-tree-dump-times "#pragma omp task 
affinity\\(iterator\\(integer\\(kind=4\\) jj=2:5:2, integer\\(kind=4\\) 
i=D\\.\[0-9\]+:5:1\\):b\\\[.* ? \\+ -1\\\]\\) 
affinity\\(iterator\\(integer\\(kind=4\\) jj=2:5:2, integer\\(kind=4\\) 
i=D\\.\[0-9\]+:5:1\\):d\\\[\\(.*jj \\* 5 \\+ .* ?\\) \\+ -6\\\]\\)" 1 
"original" } }
+! { dg-final { scan-tree-dump-times {#pragma omp task 
affinity\(iterator\(integer\(kind=4\) jj=2:5:2, integer\(kind=4\) 
i=D\.[0-9]+:5:1\):b\[.* ? \+ -1\](?:{lb: 0 sz: 4})?\) 
affinity\(iterator\(integer\(kind=4\) jj=2:5:2, integer\(kind=4\) 
i=D\.[0-9]+:5:1\):d\[\(.*jj \* 5 \+ .* ?\) \+ -6\](?:{lb: 0 sz: 4})?\)} 1 
"original" } }
 
-! { dg-final { scan-tree-dump-times "#pragma omp task 
affinity\\(iterator\\(integer\\(kind=4\\) i=D\\.\[0-9\]+:5:1\\):b\\\[.* ? 
\\+ -1\\\]\\) affinity\\(iterator\\(integer\\(kind=4\\) 
i=D\\.\[0-9\]+:5:1\\):d\\\[\\(.*i \\+ -1\\) \\* 6\\\]\\)"  1 "original" } }
+! { dg-final { scan-tree-dump-times {#pragma omp task 
affinity\(iterator\(integer\(kind=4\) i=D\.[0-9]+:5:1\):b\[.* ? \+ 
-1\](?:{lb: 0 sz: 4})?\) affinity\(iterator\(integer\(kind=4\) 
i=D\.[0-9]+:5:1\):d\[\(.*i \+ -1\) \* 6\](?:{lb: 0 sz: 4})?\)}  1 "original" } }
 ! { dg-final { scan-tree-dump-times "#pragma omp task 
affinity\\(iterator\\(integer\\(kind=4\\) i=1:5:1\\):a\\)\[^ \]" 1 "original" } 
}
 
 ! { dg-final { scan-tree-dump-times "#pragma omp task 
affinity\\(iterator\\(integer\\(kind=4\\) i=1:5:1\\):a\\) 
affinity\\(iterator\\(integer\\(kind=4\\) i=1:5:1\\):\\*x\\)"  1 "original" } }
 
-! { dg-final { scan-tree-dump-times "#pragma omp task 
affinity\\(iterator\\(integer\\(kind=4\\) k=7:4:-1, integer\\(kind=8\\) 
j=1:5:1\\):b\\\[\\(?\\(integer\\(kind=.\\).* \[jk\] \\+ .*\[kj\]\\) \\+ 
-1\\\]\\) affinity\\(iterator\\(integer\\(kind=4\\) k=7:4:-1, 
integer\\(kind=8\\) j=1:5:1\\):a\\) affinity\\(cc\\)" 1 "original" } }
+! { dg-final { scan-tree-dump-times {#pragma omp task 
affinity\(iterator\(integer\(kind=4\) k=7:4:-1, integer\(kind=8\) 
j=1:5:1\):b\[\(?\(integer\(kind=.\).* [jk] \+ .*[kj]\) \+ -1\](?:{lb: 0 sz: 
4})?\) affinity\(iterator\(integer\(kind=4\) k=7:4:-1, integer\(kind=8\) 
j=1:5:1\):a\) affinity\(cc\)} 1 "original" } }


[gcc(refs/users/mikael/heads/refactor_descriptor_v05)] Mise à jour dump bind_c_array_params_2

2025-05-25 Thread Mikael Morin via Gcc-cvs
https://gcc.gnu.org/g:e2937698ccd1ee151e1f1d0020d2244c3cc68557

commit e2937698ccd1ee151e1f1d0020d2244c3cc68557
Author: Mikael Morin 
Date:   Fri May 23 22:03:28 2025 +0200

Mise à jour dump bind_c_array_params_2

Diff:
---
 gcc/testsuite/gfortran.dg/bind_c_array_params_2.f90 | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gfortran.dg/bind_c_array_params_2.f90 
b/gcc/testsuite/gfortran.dg/bind_c_array_params_2.f90
index aa6a37b48504..f20ab9e089cd 100644
--- a/gcc/testsuite/gfortran.dg/bind_c_array_params_2.f90
+++ b/gcc/testsuite/gfortran.dg/bind_c_array_params_2.f90
@@ -30,12 +30,12 @@ end
 ! { dg-final { scan-tree-dump "parm...dtype = {.elem_len=4, .version=0, 
.rank=2, .type=1};" "original" } }
 ! { dg-final { scan-tree-dump "parm...dim\\\[0\\\].lbound = 1;" "original" } }
 ! { dg-final { scan-tree-dump "parm...dim\\\[0\\\].ubound = 4;" "original" } }
-! { dg-final { scan-tree-dump "parm...dim\\\[0\\\].stride = 1;" "original" } }
+! { dg-final { scan-tree-dump {parm...dim\[0\].spacing = 4;} "original" } }
 ! { dg-final { scan-tree-dump "parm...dim\\\[1\\\].lbound = 1;" "original" } }
 ! { dg-final { scan-tree-dump "parm...dim\\\[1\\\].ubound = 4;" "original" } }
-! { dg-final { scan-tree-dump "parm...dim\\\[1\\\].stride = 4;" "original" } }
-! { dg-final { scan-tree-dump "parm...data = \\(void \\*\\) &aa\\\[0\\\];" 
"original" } }
-! { dg-final { scan-tree-dump "parm...offset = -5;" "original" } }
+! { dg-final { scan-tree-dump {parm...dim\[1\].spacing = 16;} "original" } }
+! { dg-final { scan-tree-dump {parm...data = \(void \*\) &aa\[0\](?:{lb: 0 sz: 
4})?;} "original" } }
+! { dg-final { scan-tree-dump {parm...offset = -20;} "original" } }
 ! { dg-final { scan-tree-dump "cfi...version = 1;" "original" } }
 ! { dg-final { scan-tree-dump "cfi...rank = 2;" "original" } }
 ! { dg-final { scan-tree-dump "cfi...type = 1025;" "original" } }
@@ -47,7 +47,7 @@ end
 ! { dg-final { scan-tree-dump "if \\(idx.. <= 1\\) goto L..;" "original" } }
 ! { dg-final { scan-tree-dump "cfi...dim\\\[idx..\\\].lower_bound = 0;" 
"original" } }
 ! { dg-final { scan-tree-dump "cfi...dim\\\[idx..\\\].extent = 
\\(parm...dim\\\[idx..\\\].ubound - parm...dim\\\[idx..\\\].lbound\\) \\+ 1;" 
"original" } }
-! { dg-final { scan-tree-dump "cfi...dim\\\[idx..\\\].sm = 
parm...dim\\\[idx..\\\].stride \\* parm...span;" "original" } }
+! { dg-final { scan-tree-dump {cfi...dim\[idx..\].sm = (?:NON_LVALUE_EXPR 
<)?parm...dim\[idx..\].spacing>?;} "original" } }
 ! { dg-final { scan-tree-dump "idx.. = idx.. \\+ 1;" "original" } }
 
 ! { dg-final { scan-tree-dump "test \\(&cfi..\\);" "original" } }


[gcc r16-867] i386: Quote user-defined symbols in assembly in Intel syntax

2025-05-25 Thread Jonathan Yong via Gcc-cvs
https://gcc.gnu.org/g:5840bf969e2bfdf4f6c51d04aeb1a96a87727d80

commit r16-867-g5840bf969e2bfdf4f6c51d04aeb1a96a87727d80
Author: LIU Hao 
Date:   Sat Feb 22 13:11:51 2025 +0800

i386: Quote user-defined symbols in assembly in Intel syntax

With `-masm=intel`, GCC generates registers without % prefixes. If a
user-declared symbol happens to match a register, it will confuse the
assembler. User-defined symbols should be quoted, so they are not to
be mistaken for registers or operators.

Support for quoted symbols were added in Binutils 2.26, originally
for ARM assembly, where registers are also unprefixed:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=d02603dc201f80cd9d2a1f4b1a16110b1e04222b

This change is required for `@SECREL32` to work in Intel syntax when
targeting Windows, where `@` is allowed as part of a symbol. GNU AS
fails to parse a plain symbol with that suffix:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80881#c79

gcc/ChangeLog:

PR target/53929
PR target/80881
* config/i386/i386-protos.h (ix86_asm_output_labelref): Declare new
function for quoting user-defined symbols in Intel syntax.
* config/i386/i386.cc (ix86_asm_output_labelref): Implement it.
* config/i386/i386.h (ASM_OUTPUT_LABELREF): Use it.
* config/i386/cygming.h (ASM_OUTPUT_LABELREF): Use it.

Diff:
---
 gcc/config/i386/cygming.h |  5 +++--
 gcc/config/i386/i386-protos.h |  1 +
 gcc/config/i386/i386.cc   | 13 +
 gcc/config/i386/i386.h|  7 +++
 4 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/gcc/config/i386/cygming.h b/gcc/config/i386/cygming.h
index 743cc38f5852..0a3173c4e937 100644
--- a/gcc/config/i386/cygming.h
+++ b/gcc/config/i386/cygming.h
@@ -246,9 +246,10 @@ do {   
\
 #undef ASM_OUTPUT_LABELREF
 #define  ASM_OUTPUT_LABELREF(STREAM, NAME) \
 do {   \
+  const char *prefix = ""; \
   if ((NAME)[0] != FASTCALL_PREFIX)\
-fputs (user_label_prefix, (STREAM));   \
-  fputs ((NAME), (STREAM));\
+prefix = user_label_prefix;\
+  ix86_asm_output_labelref ((STREAM), prefix, (NAME)); \
 } while (0)
 
 /* This does much the same in memory rather than to a stream.  */
diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h
index e85b925704ba..10863ab9e9de 100644
--- a/gcc/config/i386/i386-protos.h
+++ b/gcc/config/i386/i386-protos.h
@@ -199,6 +199,7 @@ extern int ix86_attr_length_vex_default (rtx_insn *, bool, 
bool);
 extern rtx ix86_libcall_value (machine_mode);
 extern bool ix86_function_arg_regno_p (int);
 extern void ix86_asm_output_function_label (FILE *, const char *, tree);
+extern void ix86_asm_output_labelref (FILE *, const char *, const char *);
 extern void ix86_call_abi_override (const_tree);
 extern int ix86_reg_parm_stack_space (const_tree);
 
diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 5cb66dadb43e..1b7dbd425d69 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -1716,6 +1716,19 @@ ix86_asm_output_function_label (FILE *out_file, const 
char *fname,
 }
 }
 
+/* Output a user-defined label.  In AT&T syntax, registers are prefixed
+   with %, so labels require no punctuation.  In Intel syntax, registers
+   are unprefixed, so labels may clash with registers or other operators,
+   and require quoting.  */
+void
+ix86_asm_output_labelref (FILE *file, const char *prefix, const char *label)
+{
+  if (ASSEMBLER_DIALECT == ASM_ATT)
+fprintf (file, "%s%s", prefix, label);
+  else
+fprintf (file, "\"%s%s\"", prefix, label);
+}
+
 /* Implementation of call abi switching target hook. Specific to FNDECL
the specific call register sets are set.  See also
ix86_conditional_register_usage for more details.  */
diff --git a/gcc/config/i386/i386.h b/gcc/config/i386/i386.h
index 5aa056ff553b..ccc62fc3e7ca 100644
--- a/gcc/config/i386/i386.h
+++ b/gcc/config/i386/i386.h
@@ -2267,6 +2267,13 @@ extern unsigned int const 
svr4_debugger_register_map[FIRST_PSEUDO_REGISTER];
   } while (0)
 #endif
 
+/* In Intel syntax, we have to quote user-defined labels that would
+   match (unprefixed) registers or operators.  */
+
+#undef ASM_OUTPUT_LABELREF
+#define ASM_OUTPUT_LABELREF(STREAM, NAME)  \
+  ix86_asm_output_labelref ((STREAM), user_label_prefix, (NAME))
+
 /* Under some conditions we need jump tables in the text section,
because the assembler cannot handle label differences between
sections.  */


[gcc r16-868] Enable mcf thread model for aarch64-*-mingw*.

2025-05-25 Thread Jonathan Yong via Gcc-cvs
https://gcc.gnu.org/g:20aae412f824d5245c8e2520b2e38713a64c73b5

commit r16-868-g20aae412f824d5245c8e2520b2e38713a64c73b5
Author: LIU Hao 
Date:   Thu May 15 19:12:51 2025 +0800

Enable mcf thread model for aarch64-*-mingw*.

This is similar to d6d7afcdbc04adb0ec42a44b2d7e05600945af42 about the posix
and win32 thread model.

Signed-off-by: LIU Hao 
Signed-off-by: Jonathan Yong <10wa...@gmail.com>

libgcc/ChangeLog:

* config.host: Enable mcf thread model for aarch64-*-mingw*.
* config/i386/t-mingw-mcfgthread: Move to...
* config/mingw/t-mingw-mcfgthread: ...here.

Diff:
---
 libgcc/config.host   | 7 +--
 libgcc/config/{i386 => mingw}/t-mingw-mcfgthread | 0
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/libgcc/config.host b/libgcc/config.host
index 6a88ee5a2dd0..d36f0e34a3b6 100644
--- a/libgcc/config.host
+++ b/libgcc/config.host
@@ -472,6 +472,9 @@ aarch64-*-mingw*)
  posix)
tmake_thr_file="mingw/t-mingw-pthread"
;;
+ mcf)
+   tmake_thr_file="mingw/t-mingw-mcfgthread"
+   ;;
esac
tmake_file="${tmake_file} ${cpu_type}/t-no-eh ${tmake_thr_file}"
tmake_file="${tmake_file} t-dfprules"
@@ -904,7 +907,7 @@ i[34567]86-*-mingw*)
tmake_thr_file="mingw/t-mingw-pthread"
;;
  mcf)
-   tmake_thr_file="i386/t-mingw-mcfgthread"
+   tmake_thr_file="mingw/t-mingw-mcfgthread"
;;
esac
# This has to match the logic for DWARF2_UNWIND_INFO in 
gcc/config/i386/cygming.h
@@ -931,7 +934,7 @@ x86_64-*-mingw*)
tmake_thr_file="mingw/t-mingw-pthread"
;;
  mcf)
-   tmake_thr_file="i386/t-mingw-mcfgthread"
+   tmake_thr_file="mingw/t-mingw-mcfgthread"
;;
esac
# This has to match the logic for DWARF2_UNWIND_INFO in 
gcc/config/i386/cygming.h
diff --git a/libgcc/config/i386/t-mingw-mcfgthread 
b/libgcc/config/mingw/t-mingw-mcfgthread
similarity index 100%
rename from libgcc/config/i386/t-mingw-mcfgthread
rename to libgcc/config/mingw/t-mingw-mcfgthread


[gcc r16-869] Make i386 construcotr vectorizer costs more realistics

2025-05-25 Thread Jan Hubicka via Gcc-cvs
https://gcc.gnu.org/g:e3d3d6d7d2c8ab73ff597f4c82514c3217256567

commit r16-869-ge3d3d6d7d2c8ab73ff597f4c82514c3217256567
Author: Jan Hubicka 
Date:   Sun May 25 14:33:17 2025 +0200

Make i386 construcotr vectorizer costs more realistics

this patch attempts to make vectorizer costs of vector consructions more
realistic.  Currently we account one integer_to_sse cost for integer vector
construction but we over-estimate 256 and 512bit vinserts by using addss
instead of sse_op.  This is because in reality, especially on AMD machines,
vectorization of constructors may get expensive due to quite large
integer<->sse move costs.

Estimating real integer<->sse register traffic is quite hard since some of
integer non-vector arithmetics can be done in SSE registers (for example,
if there is no real arithmetics, just memory load or any code that can be
converted by scalar-to-vector RTL pass).

I think to fix the situation we need to proceed with Richi's recent patch on
adding extra info to the cost hooks and pattern match what can eventually be
STV converted. Towards that we however also need to fix current STC 
limitations
(such as lack for int->sse conversion) and make the cost mode more 
meaningful.

This patch removes the hack using addss to "add extra cost" to 256 and 
512bit
constructors.  Instead I use integer_to_sse cost in add_stmt_cost.  We 
already
account 1 consversion for all constructs (no matter of size).  I made it to 
be
2 conversions for 256 and 3 for 512 since it is closest to what we do now.

Current costs tables are not matching reality for zens
  1) SSE loads (which are pushed down from 10 cycles to 3 cycles)
  2) SSE stores
  2) SSE->integer conversion cost (which is 3 cycles instead of 5)
Similarly we are not having realistic values for Intel chips, especially
artifically increasing SSE->integer costs.

The reason is that changing those values regressed benchmarks. This was 
mostly
because these costs were accounted wrong on multiple spots and we kind of
fine-tuned for SPECs.

Other reason is that at the time the tables was merged with register 
allocator
increasing those costs led to IRA using integer registers to spill SSE 
values
and vice versa which does not work that well in practice.  I think one of
problems there is missing model for memory renaming which makes integer
spilling significantly cheaper then modelled.

In previous patches I fixed multiple issues on accounting loads and stores 
and
with this change, I hope I will be able to get the tables more realistics 
and
incrementally fix issues with individual benchmarks.

I benchmarked the patch wtih -Ofast -march=native -flto on znver5 and 
skylake.
It seems in noise for skylake, for znver5 I got what seems off-noise for
xalabcbmk 8.73->8.81 (rate). Rest seems in noise too,
however the change affects quite some SLP decisions when the sequence is
just loads followed by vector store.

gcc/ChangeLog:

* config/i386/i386.cc (ix86_builtin_vectorization_cost):
use sse_op instead of addss to cost vinsertti128 and vinsertti64x4;
compute correct mode of vinsertti128.
(ix86_vector_costs::add_stmt_cost): For integer 256bit and 512bit
vector constructions account more integer_to_sse moves.

Diff:
---
 gcc/config/i386/i386.cc | 29 +
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc
index 1b7dbd425d69..d48654a729a1 100644
--- a/gcc/config/i386/i386.cc
+++ b/gcc/config/i386/i386.cc
@@ -25185,12 +25185,18 @@ ix86_builtin_vectorization_cost (enum 
vect_cost_for_stmt type_of_cost,
  /* One vinserti128 for combining two SSE vectors for AVX256.  */
  else if (GET_MODE_BITSIZE (mode) == 256)
return ((n - 2) * ix86_cost->sse_op
-   + ix86_vec_cost (mode, ix86_cost->addss));
+   + ix86_vec_cost (mode, ix86_cost->sse_op));
  /* One vinserti64x4 and two vinserti128 for combining SSE
 and AVX256 vectors to AVX512.  */
  else if (GET_MODE_BITSIZE (mode) == 512)
-   return ((n - 4) * ix86_cost->sse_op
-   + 3 * ix86_vec_cost (mode, ix86_cost->addss));
+   {
+ machine_mode half_mode
+   = mode_for_vector (GET_MODE_INNER (mode),
+  GET_MODE_NUNITS (mode) / 2).require ();
+ return ((n - 4) * ix86_cost->sse_op
+ + 2 * ix86_vec_cost (half_mode, ix86_cost->sse_op)
+ + ix86_vec_cost (mode, ix86_cost->sse_op));
+   }
  gcc_unreachable ();
}
 
@@ -26048,7 +26054,22 @@ ix86_vector_costs::add_stmt_cost (int count, 
vect_cost_for_stmt kind,
  else